[Django]-In the Django admin is it possible to separate models into sub-models based on groups?

8👍

There is a way. This involves using a proxy model for one (or both) type of images. You can then add separate admins for the two. For e.g.

# models.py
class ProfileImage (Image):
    class Meta:
        proxy = True

class GalleryImage (Image):
    class Meta:
        proxy = True

This will avoid creating new tables. You’ll still be storing all the data in the table corresponding to the Image model. You can then register two different admins for these proxies.

# admin.py
class ProfileImageAdmin (ImageAdmin):
    def queryset(self, request):
        qs = super(MyModelAdmin, self).queryset(request)
        return qs.filter(type='profile')

class GalleryImageAdmin (ImageAdmin):
    def queryset(self, request):
        qs = super(MyModelAdmin, self).queryset(request)
        return qs.filter(type='gallery')

admin.site.register(ProfileImage, ProfileImageAdmin)
admin.site.register(GalleryImage, GalleryImageAdmin)

Leave a comment