Hi,
just encountered this same problem today.
As Roman reported in ticket-32484 
<https://code.djangoproject.com/ticket/32482>:

> Sometimes model names are so unfortunate that default alphabetical order 
> of models in contrib.admin application makes no sense at all.
> The same applies to applications themselves. When there are many 
> applications or many models within application there is a natural need to 
> group them up logically.
>
> Reordering of models is covered in many online resources, but the very 
> process is so inconsistent and complex, that few get it right.
>
I would like to propose the following solution:

We add a new method order_models (or sort_models) to class admin.AdminSite. 
This method then sorts the models according to its own
logic and defaults to models.sort(key=lambda x: x["name"]). Whenever 
someone wants to sort his models otherwise, he just has to
override this method. This new method then is called by 
AdminSite.get_app_list and AdminSite.app_index.

The alternative I had to use today, was to override both methods, 
get_app_list and app_index to override just the model sorting part –
I therefore had to copy & paste 30 lines of Django code to replace just one 
function!

It btw. is much DRYer to implement the sorting of something into an 
external overridable method, rather than implementing this twice, as in both
methods just mentioned.

If the named ticket is reopened, I will implement this.

– Jacob

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/196da0a6-2ad7-4067-b893-64fb987483e9n%40googlegroups.com.

Reply via email to