Let’s imagine the following model:
class Photo(models.Model):
class Type(models.IntegerChoices):
LANDSCAPE = 1, 'Landscape'
CLOSEUP = 2, 'Close-up'
# etc...
type = models.PositiveSmallIntegerField('Type', blank=False, null=False, choices=Type.choices, default=Type.LANDSCAPE, db_column='t')
And in the corresponding admin.py
:
class PhotoLandscapeAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return super(PhotoLandscapeAdmin, self).get_queryset(request).filter(
type=Photo.Type.LANDSCAPE
)
class PhotoCloseupAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return super(PhotoCloseupAdmin, self).get_queryset(request).filter(
type=Photo.Type.CLOSEUP
)
admin.site.register(Photo, PhotoLandscapeAdmin)
admin.site.register(Photo, PhotoCloseupAdmin)
and I get:
django.contrib.admin.sites.AlreadyRegistered: The model Photo is already registered with 'photo.PhotoLandscapeAdmin'.
Is there a way to do this? i.e, to have two “entries” in the admin panel/menu?
I know something very similar can be done via filters and what not, but having those two “shortcuts” would be very useful.
Thanks!