Register same model twice on admin - is there a way?

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

class PhotoLandscapeAdmin(admin.ModelAdmin):
        def get_queryset(self, request):
            return super(PhotoLandscapeAdmin, self).get_queryset(request).filter(

class PhotoCloseupAdmin(admin.ModelAdmin):
        def get_queryset(self, request):
            return super(PhotoCloseupAdmin, self).get_queryset(request).filter(
            ), PhotoLandscapeAdmin), 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! :slight_smile:

Yes, it can be done with a proxy model.

See Models | Django documentation | Django and the related thread about the admin at Multiple ModelAdmins/views for same model in Django admin

1 Like

Sure do!
But you need to create a ProxyModel for that.
You can do that by adding these to your

# Create a class with another name, that inherits from the Photo model
# It must have proxy = True on the Meta class
class OtherTypePhoto(Photo):
    class Meta:
        proxy = True

Then register the proxied model on the, PhotoCloseupAdmin)

nice, thanks :slight_smile:
[20 characters]