Opened 10 years ago

Closed 6 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: master
Severity: Keywords: nfa-changelist
Cc: djangotrac@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

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@… 10 years ago.
Diff against trunk
admin_list.diff (1.4 KB) - added by kent37@… 10 years ago.
Patch to allow descending sort of non-DB fields
patch_allow_ordering_by_nonfields_fix.diff (610 bytes) - added by anonymous 10 years ago.

Download all attachments as: .zip

Change History (20)

Changed 10 years ago by marcink@…

Diff against trunk

comment:1 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedDesign decision needed

Seems useful.

comment:2 Changed 10 years ago by marcink@…

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 Changed 10 years ago by Malcolm Tredinnick

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 Changed 10 years ago by Jacob

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 Changed 10 years ago by kent@…

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.

Changed 10 years ago by kent37@…

Attachment: admin_list.diff added

Patch to allow descending sort of non-DB fields

comment:6 Changed 10 years ago by Jacob

Resolution: fixed
Status: reopenedclosed

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

Changed 10 years ago by anonymous

comment:7 Changed 10 years ago by glin@…

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 Changed 9 years ago by marcin@…

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 Changed 9 years ago by Simon G. <dev@…>

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 Changed 9 years ago by Gary Wilson

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

comment:11 Changed 9 years ago by Gary Wilson

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 Changed 9 years ago by jakub_vysoky

Keywords: nfa-changelist added

comment:14 Changed 8 years ago by Brian Rosner

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

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

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 Changed 8 years ago by Marco Bazzani

Cc: djangotrac@… added

comment:17 Changed 6 years ago by Ramiro Morales

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 Changed 6 years ago by Karen Tracey

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