Opened 17 years ago
Closed 14 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 by , 17 years ago
by , 17 years ago
Attachment: | ordering_patch_main.py.diff added |
---|
comment:2 by , 17 years ago
Has patch: | set |
---|
comment:3 by , 17 years ago
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 17 years ago
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 by , 17 years ago
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 by , 17 years ago
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?
follow-up: 18 comment:8 by , 17 years ago
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 by , 17 years ago
Triage Stage: | Unreviewed → Someday/Maybe |
---|
comment:10 by , 17 years ago
Keywords: | nfa-changelist added |
---|
comment:11 by , 17 years ago
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.
by , 17 years ago
Attachment: | ticket_4926_changelist_multifield_ordering.diff added |
---|
comment:12 by , 16 years ago
Cc: | 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 by , 16 years ago
Cc: | added |
---|
comment:14 by , 16 years ago
Cc: | added |
---|
comment:15 by , 15 years ago
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 by , 15 years ago
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 by , 15 years ago
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.
by , 15 years ago
Attachment: | ticket_4926_changelist_multifield_ordering_r12379.diff added |
---|
patch against current trunk, otherwise unmodified
by , 15 years ago
Attachment: | ticket_4926_changelist_multifield_ordering_r12379.2.diff added |
---|
also removes the related admonition from contrib.admin documentation
comment:18 by , 15 years ago
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 by , 15 years ago
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 by , 15 years ago
Cc: | added |
---|
comment:22 by , 14 years ago
Cc: | added |
---|
comment:23 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:24 by , 14 years ago
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.