Django

Code

Ticket #4926 (reopened)

Opened 1 year ago

Last modified 3 months ago

Ordering in admin listview ignores ordering in admin options

Reported by: Glin <glin@seznam.cz> Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords: nfa-someday nfa-changelist
Cc: smoonen@andstuff.org Triage Stage: Someday/Maybe
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When I specify ordering in admin options like this:

class ArticleOptions(admin.ModelAdmin):
    list_display = ('title', 'is_news', 'published_from_date')
    ordering = ('is_news', 'pub_date')

Ordering set default ordering column to 'is_news', but doesn't take 'pub_date' into account.

Generally all other fields except first specified in ordering tuple are ignored.

Attachments

ordering_patch_main.py.diff (0.5 kB) - added by Glin <glin@seznam.cz> on 07/19/07 09:50:40.
ticket_4926_changelist_multifield_ordering.diff (0.7 kB) - added by Eric B <ebartels@gmail.com> on 05/01/08 16:36:09.

Change History

07/19/07 09:50:28 changed by Glin <glin@seznam.cz>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

It is because query.order_by rewrites previous ordering. In this case, it is on this line:

qs = qs.order_by(order_type + lookup_order_field)

So ordering from 'ordering' admin options are not taken in account (and 'ordering' from Meta, too).

I created a patch for this.

07/19/07 09:50:40 changed by Glin <glin@seznam.cz>

  • attachment ordering_patch_main.py.diff added.

07/19/07 09:50:56 changed by Glin <glin@seznam.cz>

  • has_patch set to 1.

09/14/07 17:20:54 changed by jkocherhans

(In [6232]) newforms-admin: Fixed ordering for ModelAdmin?.queryset. Refs #4926, but that ticket still needs ModelAdmin?.changelist_view to use ModelAdmin?.queryset.

09/14/07 17:41:11 changed by jkocherhans

  • status changed from new to closed.
  • resolution set to fixed.

(In [6239]) newforms-admin: Fixed a problem with [6232] where an exception was raised if ModelAdmin? didn't specify ordering. Also, fixed #4926.

10/23/07 05:35:06 changed by Glin <glin@seznam.cz>

  • status changed from closed to reopened.
  • resolution deleted.

Unfortunately this did not solve the problem.

Problem is that any order_by() call deletes ordering of previous order_by() call (e.g. qs.order_by('is_news').order_by('pub_date') is the same as qs.order_by('pub_date') ).

So problem must be fixed in code of ChangeList? class, because there is the last call of order_by method. (as in my patch)

10/24/07 12:08:30 changed by ramiro

See ticket #5673 and this discussion http://groups.google.com/group/django-developers/browse_frm/thread/c74afae800fda0b9?tvc=1 for a discussion about multi-column ordering in the admin UI (it's not about the admin app ordering option bout about the model's Meta.ordering setting though).

10/25/07 02:59:14 changed by Glin <glin@seznam.cz>

I looked at it, initial comment is nearly about the same issue as this ticket (later in discussion, there is mentioned multi column sorting in way that user can influence these sorting columns.)

My patch only solves first issue, so admin still sorts primary according to one column selected by user, and other sorting columns are immutable (they are specified in model_admin.ordering). So it is only small (one and half line) patch, so way don't use this?

12/10/07 11:25:47 changed by brosner

  • keywords set to nfa-someday.

This ticket isn't critical to the merge of newforms-admin since it is an enhancement. Tagging with nfa-someday.

03/17/08 10:32:26 changed by anonymous

  • stage changed from Unreviewed to Someday/Maybe.

03/19/08 00:11:24 changed by ales_zoulek

  • keywords changed from nfa-someday to nfa-someday nfa-changelist.

05/01/08 16:35:17 changed by Eric B <ebartels@gmail.com>

I realized this is considered not to be critical for merging, but I'm submitting a new patch against the latest code.

Here's the new behavior: In the case where multiple fields are specified, that ordering will be respected by default. In this case, the changelist won't show a single table column as being sorted until a column header has been clicked.

This seems much more consistent to me than the current behavior. It's a little confusing that ModelAdmin? requires ordering as a tuple/list of fields, and then ignores all but the first field.

05/01/08 16:36:09 changed by Eric B <ebartels@gmail.com>

  • attachment ticket_4926_changelist_multifield_ordering.diff added.

07/19/08 22:37:01 changed by smoonen@andstuff.org

  • cc set to smoonen@andstuff.org.
  • version changed from newforms-admin to SVN.

Me-too (now that nfa has hit the trunk). Most of my models have multiple fields in their ordering. Changing the version of this ticket to 'SVN' now that nfa is on trunk.


Add/Change #4926 (Ordering in admin listview ignores ordering in admin options)




Change Properties
Action