django-admin-interface icon indicating copy to clipboard operation
django-admin-interface copied to clipboard

App model order for Admin Interface

Open saymoncoppi opened this issue 4 years ago • 5 comments

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

image

Originally posted by @saymoncoppi in https://github.com/fabiocaccamo/django-admin-interface/issues/117#issuecomment-963169383

saymoncoppi avatar Nov 26 '21 01:11 saymoncoppi

Would be nice if this included hiding some app or specific models!

merwok avatar Dec 03 '21 21:12 merwok

It would be nice to manage all this from the admin itself.

fabiocaccamo avatar Dec 03 '21 21:12 fabiocaccamo

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 avatar Dec 03 '21 22:12 merwok

@merwok if you only need to hide Groups you can just unregister the ModelAdmin, eg. admin.site.unregister(Group)

fabiocaccamo avatar Dec 03 '21 22:12 fabiocaccamo

Ah of course 😄 The app and model would still be enabled, just hidden in admin. Ignore my message!

merwok avatar Dec 03 '21 22:12 merwok

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 avatar Sep 27 '22 07:09 derzinn

@derzinn cool, thank you for the suggestion!

fabiocaccamo avatar Sep 27 '22 07:09 fabiocaccamo

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

fabiocaccamo avatar Sep 27 '22 07:09 fabiocaccamo

@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 avatar Sep 27 '22 08:09 derzinn

@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 avatar Sep 27 '22 08:09 fabiocaccamo

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

derzinn avatar Sep 27 '22 08:09 derzinn

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

merwok avatar Sep 27 '22 14:09 merwok

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?

fabiocaccamo avatar Sep 27 '22 15:09 fabiocaccamo

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?

merwok avatar Sep 27 '22 16:09 merwok

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!

merwok avatar Feb 17 '23 23:02 merwok