django-admin-interface
django-admin-interface copied to clipboard
App model order for Admin Interface
Hello Fabio!!! Today I saw an improvement that fits with this old suggestion. Beyond the foldable option could the django-admin-interface offer a way to reorder classes on tree menu. Take a look https://stackoverflow.com/questions/398163/ordering-admin-modeladmin-objects

Originally posted by @saymoncoppi in https://github.com/fabiocaccamo/django-admin-interface/issues/117#issuecomment-963169383
Would be nice if this included hiding some app or specific models!
It would be nice to manage all this from the admin itself.
Settings would be enough for me. For me it’s about the app definition (for example, this project doesn’t use groups so don’t show them in admin), not appearance customization. But I can see the other viewpoint!
@merwok if you only need to hide Groups you can just unregister the ModelAdmin, eg. admin.site.unregister(Group)
Ah of course 😄 The app and model would still be enabled, just hidden in admin. Ignore my message!
Just for the record: django-modeladmin-reorder works without problems in Django 4.1 and Python 3.10.
This package currently has no active maintainers, but an ownership change is in progress.
@derzinn cool, thank you for the suggestion!
@derzinn I see the library you suggested has not been updated since many years and it has not tests, anyway it's a good reference for adding this feature directly into django-admin-interface.
@derzinn I see the library you suggested has not been updated since many years and it has not tests, anyway it's a good reference for adding this feature directly into
django-admin-interface.
Yes, the codebase is a "little bit" outdated. :grin: But runs fine.
And it is very useful, for example:
ADMIN_REORDER = (
'sites',
{
'app': 'auth',
'models': (
'custom_auth.User',
'auth.Group',
)
},
)
Including features like cross-linking and renaming models would be really cool! :+1:
@derzinn indeed!
What do you think about making this configuration editable directly in the admin using a JSONField? (it would require to add django-json-widget dependency).
@fabiocaccamo Great idea! :+1:
So a drag-and-drop widget can be added later to sort and hide existing apps/models right from the interface.
Django 4.1 lets us reorder models in the admin! https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.AdminSite.get_app_list
Oh nice, didn't know about that.
Do you think we can close this issue?
Or this app should use the get_app_list method for an optimal integration?
I would say that defining order of models is part of making the admin adapted to specific project needs, so it’s fine to do it with code and have it be the same for all themes. What do other people think?
It was actually added in 4.0 I think!
I’ve implemented it in a project with a custom AdminSite subclass implementing get_app_list using a hard-coded list of sorted app names + custom attribute _order_ on model classes so that each app can define order for models.
It’s OK but not great.
To do it with django-admin-interface, we’d need a way to store order, for example a JSON field, and a custom AdminSite subclass that uses it. The rainbow pony would be a fancy list widget that automatically lists all apps and models, with drag-n-drop interface, but that’s a bit of javascript work!