Open LeOndaz opened 1 year ago
from django.contrib import admin from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter from .models import Device, DeviceSubscribedEmail, Hub, Plug, PlugMini class DeviceChildAdmin(PolymorphicChildModelAdmin): show_in_index = False def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False @admin.register(Plug) class PlugAdmin(DeviceChildAdmin): base_model = Plug class EmailSubscribersInline(admin.StackedInline): model = DeviceSubscribedEmail extra = 1 @admin.register(PlugMini) class PlugMiniAdmin(DeviceChildAdmin): base_model = PlugMini fieldsets = [ ("info", {"fields": ["id", "name", "country", "hub_device", "is_powered_on"]}), ( "usage", {"fields": ["electricity_of_day", "voltage", "weight", "electric_current"]}, ), ("thresholds", {"fields": ["weight_threshold"]}), ] inlines = [EmailSubscribersInline] @admin.register(Hub) class HubAdmin(DeviceChildAdmin): pass @admin.register(Device) class DeviceAdmin(PolymorphicParentModelAdmin): base_model = Device child_models = [PlugMini, Plug, Hub] list_filter = [PolymorphicChildModelFilter] def has_add_permission(self, request): return False
All models inherit from Device model which is a PolymorphicModel and still, all models show up in the admin page.
Device
PolymorphicModel
Looks like duplicate of https://github.com/django-polymorphic/django-polymorphic/issues/497 See also workaround https://github.com/django-polymorphic/django-polymorphic/issues/497#issuecomment-1214241133
All models inherit from
Device
model which is aPolymorphicModel
and still, all models show up in the admin page.