Opened 16 years ago
Closed 13 years ago
#4926 closed Bug (duplicate)
Ordering in admin listview ignores ordering in admin options
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | nfa-someday nfa-changelist |
Cc: | smoonen@…, james.m.pearson+django@…, django@…, rob@…, Patrick Kranzlmueller | Triage Stage: | Someday/Maybe |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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 (4)
Change History (28)
comment:1 Changed 16 years ago by
Changed 16 years ago by
Attachment: | ordering_patch_main.py.diff added |
---|
comment:2 Changed 16 years ago by
Has patch: | set |
---|
comment:3 Changed 16 years ago by
comment:4 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 Changed 16 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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)
comment:6 Changed 16 years ago by
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).
comment:7 Changed 16 years ago by
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?
comment:8 follow-up: 18 Changed 16 years ago by
Keywords: | nfa-someday added |
---|
This ticket isn't critical to the merge of newforms-admin since it is an enhancement. Tagging with nfa-someday.
comment:9 Changed 16 years ago by
Triage Stage: | Unreviewed → Someday/Maybe |
---|
comment:10 Changed 16 years ago by
Keywords: | nfa-changelist added |
---|
comment:11 Changed 16 years ago by
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.
Changed 16 years ago by
Attachment: | ticket_4926_changelist_multifield_ordering.diff added |
---|
comment:12 Changed 15 years ago by
Cc: | smoonen@… added |
---|---|
Version: | newforms-admin → 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.
comment:13 Changed 15 years ago by
Cc: | james.m.pearson+django@… added |
---|
comment:14 Changed 15 years ago by
Cc: | django@… added |
---|
comment:15 Changed 14 years ago by
This seems like an easy fix without many consequences to me. It would be nice to either get this merged in (or a "this should go in, but the patch needs work") or a wontfix close. If the previous is the case, I'm willing to work on it. If the latter, then it'll just be nice to have a resolution of some sort.
comment:16 Changed 14 years ago by
This is a very useful feature (especially for django-mptt users) and the patch seems quite unobtrusive, +1 for merging it into trunk
comment:17 Changed 14 years ago by
If anyone is interested, I've submitted a patch for a proposed UI for sorting by multiple fields. This would also fix this particular issue.
See here: #11868
Any feedback is appreaciated.
Changed 14 years ago by
Attachment: | ticket_4926_changelist_multifield_ordering_r12379.diff added |
---|
patch against current trunk, otherwise unmodified
Changed 14 years ago by
Attachment: | ticket_4926_changelist_multifield_ordering_r12379.2.diff added |
---|
also removes the related admonition from contrib.admin documentation
comment:18 Changed 14 years ago by
Replying to brosner:
This ticket isn't critical to the merge of newforms-admin since it is an enhancement. Tagging with nfa-someday.
I'd consider this a little more than an enhancement. As Eric B noted, it's confusing that a tuple/list of fields is required but all but the first field are ignored.
comment:19 Changed 14 years ago by
I agree.
This for me, is most certainly a bug...
For example, I have a set of teams and each team has a set of players with numbers.
I would like to order them by team and then by number but the following does not do that.
ordering=('team','number')
In fact any number of fields are irrelevant given it really only ever orders like this:
ordering=('team')
The behavior is just wrong so for me it's a bug, not an enhancement.
comment:20 Changed 14 years ago by
Cc: | rob@… added |
---|
comment:22 Changed 13 years ago by
Cc: | Patrick Kranzlmueller added |
---|
comment:23 Changed 13 years ago by
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:24 Changed 13 years ago by
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Closing as a duplicate of #11868 which, although newer, suggests a better approach UI-wise and has a more recent patch.
It is because query.order_by rewrites previous ordering. In this case, it is on this line:
So ordering from 'ordering' admin options are not taken in account (and 'ordering' from Meta, too).
I created a patch for this.