Reputation: 195
Is there any way to group the models in django admin interface?
I currently have an app called requests with the following models showing in the admin site:
**Requests**
Divisions
Hardware Requests
Hardware Types
Requests
Software Requests
Software Types
I would like the divisions, Software Requests and Hardware Requests to be grouped separately in a "Types" group. I know I could override and hard code the admin/index.html and base_site.html but this seems rather convoluted just to specify grouping.
Is there anything i can add to the Meta class to specify a group name?
The only way I have found so far to achieve what i want is to move the models to a new app within requests ("requests.Types") but again, doesn't feel like its the 'correct way'.
Upvotes: 18
Views: 8166
Reputation: 2368
You can do it using django-modeladmin-reorder.
You'd configure it somehow along these lines then (settings.py):
ADMIN_REORDER = (
{'app': 'requests', 'label': 'Types',
'models': (
'requests.Divisions',
'requests.HardwareRequests',
'requests.HardwareTypes'
)
},
{'app': 'requests', 'label': 'Other models',
'models': (
'requests.Requests',
'requests.SoftwareRequests',
'requests.SoftwareTypes'
)
},
)
Upvotes: 14
Reputation: 11163
There isn't anything you can put in the model definition to do this, because models -- by design -- don't know about the existence of the admin, or how they'll be presented in the admin.
This really is a case where you just write a template that does what you want, and use it; all you're asking for is a presentational change, and templates are where you do presentation in Django.
Upvotes: 9