Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group models in django admin

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'.

like image 606
Morchuboo Avatar asked Apr 14 '09 16:04

Morchuboo


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.

What is group and user in Django?

Django does provide groups and permissions option but this is a model or table level and not at the object level. Hence we decided on creating groups based on the objects on which we want to provide the access and the users were added to these groups as per requirement or based on the existing state of an object.


1 Answers

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'
        )
   },
)
like image 199
jox Avatar answered Oct 11 '22 11:10

jox