Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group models in django admin?

Tags:

Lets say I have a group of models that must be kept separate (visually) in the admin from another group.

Right now they are alphabetic, which jumbles them.

I'd like to organize them this way:


Group 1: (custom named)

  • Model 1
  • Model 4

Group 2 (custom named)

  • Model 2
  • Model 3

I cannot seem to find the documentation on how to do this. Is this even possible?

like image 212
1Up Avatar asked Jul 11 '15 01:07

1Up


People also ask

WHAT IS group in Django admin?

Groups are a means of categorizing users. This allows for granting permissions to a specific group.


1 Answers

I do not think that splitting up your business logic, i.e. your app, when all you want to achieve is some kind of markup is the right way. Instead I found the Python package django-modeladmin-reorder that lets you achieve this easily. You can combine its feature of labelling apps and reordering models to group models of one app in the admin. After following the installation instructions, add something like this to your settings.py

ADMIN_REORDER = (     # First group     {'app': 'myapp', 'label': 'Group1',      'models': ('myapp.Model_1',                 'myapp.Model_4',)     },     # Second group: same app, but different label     {'app': 'myapp', 'label': 'Group2',      'models': ('myapp.Model_2',      'myapp.Model_3',)     },) 
like image 173
Jarno Avatar answered Sep 24 '22 18:09

Jarno