Re: [Django] #35302: Property on AppConfig and ModelAdmin for ordering apps and models in admin sidebar

2024-03-14 Thread Django
#35302: Property on AppConfig and ModelAdmin for ordering apps and models in 
admin
sidebar
-+-
 Reporter:  Michał Pokusa|Owner:  Michał
 |  Pokusa
 Type:  New feature  |   Status:  closed
Component:  contrib.admin|  Version:  dev
 Severity:  Normal   |   Resolution:  wontfix
 Keywords:  admin models apps| Triage Stage:
  ordering reorder sidebar move  |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  1|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * resolution:   => wontfix
 * status:  assigned => closed

Comment:

 Thanks for this ticket, however in #7497 we
 [https://code.djangoproject.com/ticket/25671#comment:11 decided] that in
 most of cases `get_app_list()` is enough to change the default order and
 we're not going to add any new options around that.
-- 
Ticket URL: 
Django 
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/0107018e4097b969-3d4fd154-d745-4a7c-919f-2b915c5fc6ed-00%40eu-central-1.amazonses.com.


[Django] #35302: Property on AppConfig and ModelAdmin for ordering apps and models in admin sidebar

2024-03-14 Thread Django
#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: 
Django 
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-00%40eu-central-1.amazonses.com.