Opened 18 years ago

Closed 14 years ago

#3397 closed (fixed)

Add tests for 'Allow DB-level ordering by non-fields in changelist view' admin functionality

Reported by: marcink@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords: nfa-changelist
Cc: djangotrac@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The attached patch lets you specify a field to sort a non-field
column in the admin list view. I created it for the django-multilingual
library, but there are more cases where this could prove useful.
See the example in docs/model-api.txt diff.

Attachments (3)

patch_allow_ordering_by_nonfields.diff (5.2 KB ) - added by marcink@… 18 years ago.
Diff against trunk
admin_list.diff (1.4 KB ) - added by kent37@… 18 years ago.
Patch to allow descending sort of non-DB fields
patch_allow_ordering_by_nonfields_fix.diff (610 bytes ) - added by anonymous 18 years ago.

Download all attachments as: .zip

Change History (20)

by marcink@…, 18 years ago

Diff against trunk

comment:1 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

Seems useful.

comment:2 by marcink@…, 18 years ago

Summary: [patch] Allow ordering by non-fields in admin list view[patch] Allow DB-level ordering by non-fields in admin list view

Renamed the ticket to clarify it.

comment:3 by Malcolm Tredinnick, 18 years ago

Triage Stage: Design decision neededReady for checkin

This seems reasonable. It's a little bit hard to understand until you read the docs, but the example gets the point across. The documentation paragraph probably needs a rewrite -- it feels a bit awkward at the moment. But I'm too tired to get it right now; we just need to remember to tweak that before checking in. Other than that, this looks fine.

comment:4 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

(In [4596]) Fixed #3397: You can now order by non-DB fields in the admin by telling Django which field to actually order by. Thanks, marcink@…

comment:5 by kent@…, 18 years ago

Resolution: fixed
Status: closedreopened
Triage Stage: Ready for checkinUnreviewed

This doesn't quite work correctly. It allows clicking on the column title to sort in ascending order but it doesn't display the triangle and a second click will sort ascending rather than descending.

The fix is for admin_list.py line 104 to also check if the admin_order_field equals cl.order_field.

Patch attached.

by kent37@…, 18 years ago

Attachment: admin_list.diff added

Patch to allow descending sort of non-DB fields

comment:6 by Jacob, 18 years ago

Resolution: fixed
Status: reopenedclosed

(In [5318]) Fixed #3397 (again): admin_order_field is now displayed correctly in the admin views. Thanks, kent37@…

comment:7 by glin@…, 18 years ago

Resolution: fixed
Status: closedreopened

Unless I'm mistaken, in django/contrib/admin/views/main.py in section added in this patch, there(see my patch patch_allow_ordering_by_nonfields_fix.diff) should be AttributeError instead of IndexError (IndexError cannot raise there and IMO author meant there AttributeError)

comment:8 by marcin@…, 17 years ago

glin: you are right, it should be an AttributeError. I missed it because usually this code path is not executed at all, but it is a bug and should be fixed.

comment:9 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedReady for checkin

The file "patch_allow_ordering_by_nonfields_fix.diff" should be checked in following the last two comments (i.e. should be AttributeError not IndexError.

comment:10 by Gary Wilson, 17 years ago

(In [5799]) Refs #3397 -- Corrected the Exception that is caught when ordering by non-fields (added in [4596]), thanks glin@….

comment:11 by Gary Wilson, 17 years ago

Has patch: unset
Needs tests: set
Triage Stage: Ready for checkinAccepted

Just because the other parts of the admin don't have tests doesn't mean that we should continue the trend.

comment:13 by jakub_vysoky, 17 years ago

Keywords: nfa-changelist added

comment:14 by Brian Rosner, 16 years ago

Can someone verify if this broken on trunk? It sounds likely it will work just fine, but needs really needs a test case.

in reply to:  14 comment:15 by Karen Tracey <kmtracey@…>, 16 years ago

Replying to brosner:

Can someone verify if this broken on trunk? It sounds likely it will work just fine, but needs really needs a test case.

Verified the function works correctly on trunk [8169]. I guess the ticket was just reopened because the function lacks a test.

comment:16 by Marco Bazzani, 16 years ago

Cc: djangotrac@… added

comment:17 by Ramiro Morales, 14 years ago

Summary: [patch] Allow DB-level ordering by non-fields in admin list viewAdd tests for 'Allow DB-level ordering by non-fields in changelist view' admin functionality

comment:18 by Karen Tracey, 14 years ago

Resolution: fixed
Status: reopenedclosed

In the intervening years since this was reopened, tests have been added for admin_order_field, see for example: http://code.djangoproject.com/browser/django/tags/releases/1.2.5/tests/regressiontests/admin_views/tests.py#L192

I think it's OK to close this one as fixed now.

Note: See TracTickets for help on using tickets.
Back to Top