Custom Admin Apps for grouping and reordering Models

As the numbers Models in an app grows, it becomes tedious to find the model we are searching for in a long list on the index page (and navigation bar) of the Django admin

As a part of a new project, I wanted to reorder and logically group models that do not necessarily reflect the apps of the project. I found this little library called django-modeladmin-reorder that does it by remapping the fields with a middleware.

However, I think it would be cleaner if Django supported it natively as this can be useful in almost every project. A layer called AdminApp between the admin and the ModelAdmin registered would be the perfect middle ground.

Proposal

  • Create a new class in admin called AdminApp
    • The AdminApp should be registerable to admin
    • The AdminApp should accept ModelAdmin to be registered with it
  • Wire up the ModelAdmins and AdminApps to see custom layout that is not tied to apps
  • For all ModelAdmins registered directly to admin, fallback to current implementation
# Option 1
class AgencyAdmin(admin.ModelAdmin):
   ...

class AgencyConfigAdmin(admin.ModelAdmin):
   ...

class AgencyAdminApp(admin.AdminApp):
   label = "Agency Details"

class AgentAdmin(admin.ModelAdmin):
   ...

admin.register(AgentAdmin, Agent) # Existing implementation

## Add Models to AdminApp
admin.add_app(AgencyAdminApp)
admin.register_app(AgencyAdminApp, AgencyAdmin)
admin.register_app(AgencyAdminApp, AgencyConfigAdmin)

# Option 2 
@register(Agency, admin_app=AgencyAdminApp)
class AgencyAdmin(admin.ModelAdmin):
  ...

@register(AgencyConfig, admin_app=AgencyAdminApp)
class AgencyConfigAdmin(admin.ModelAdmin):
   ....

I feel like this seems like a decent middle ground that doesn’t break existing implementation but allows the app to be expanded in the future.

So what do you think about the idea? If the core team is interested, I’ll be more than willing to work on this but I am first time contributor and will need some mentoring on it.

See https://groups.google.com/g/django-developers/c/NnzoO_TSWgo/m/cKF1xTPpBQAJ