#35302: Property on AppConfig and ModelAdmin for ordering apps and models in admin sidebar -------------------------------------+------------------------------------- Reporter: Michał | Owner: Michał Pokusa Pokusa | Type: New | Status: assigned feature | Component: | Version: dev contrib.admin | Keywords: admin models apps Severity: Normal | ordering reorder sidebar move Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 1 UI/UX: 0 | -------------------------------------+------------------------------------- Currently apps and models registered are sorted only based on "name" that comes from `AdminSite._build_app_dict`.
There is no easy way of reordering models and/or app in the sidebar. Solutions found online suggest overriding `AdminSite.get_app_list`, but even this approach is not perfect as it uses the `dict` from `AdminSite._build_app_dict`, which contains limited information about apps and its models. I remember even finding a solution that used JavaScript for manual reordering of DOM elements. Seems like there are many people, including me, that want to reorder the admin sidebar, I assume for more logical placement of models. Example where this makes sense is an app with "Question" and "Answer" models, where "Answers" will be sorted before "Questions", despite the opposite making more sense. Another example is moving main business logic apps to the top, where they are easily accessible and moving less often used apps to the bottom. I propose adding a new property, e.g. "sidebar_order" (`0` by default) or something like this, that could be set on `AppConfig` and `ModelAdmin` and would have priority when determinining the order in admin sidebar and/or model listing when accesing specific app's admin. If it is not provided, the standard ordering based on name would take effect. I believe this would fit with current similar Django options, like `ordering`, `list_display`, custom order of filters etc. Example: {{{ @admin.register(Question) class QuestionAdmin(admin.ModelAdmin): sidebar_order = 1 ... @admin.register(Answer) class AnswerAdmin(admin.ModelAdmin): sidebar_order = 2 ... }}} My proposed solution would be 100% backwards compatible. This change requires literally change in 4 lines in `django.contrib.admin.sites` for it to work (that is why i mark it as Easy picking), of course more for proper implementation. Also it would be easy to add ordering to new models without changing the ordering of all other models, as one could set the property to values like `10`, `20` instead of `1`, `2`, which would allow setting new models ordering to any value between e.g. `15`. -- Ticket URL: <https://code.djangoproject.com/ticket/35302> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e3fe556dd-d307fff5-81db-4f07-a02f-4fb5ea8ac94b-000000%40eu-central-1.amazonses.com.