Opened 15 years ago

Closed 13 years ago

#12875 closed New feature (fixed)

Cannot redefine admin ordering dynamically

Reported by: Manuel Saelices Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Sometimes you need redefine ordering dinamically, based in some logic at runtime

A example of that needed was this code:

class MyBaseAdmin(admin.ModelAdmin):

   def get_ordering(self, request):
      # I'd like i.e. a different order based on user or whatever
      if request.user.is_superuser():
         ...
      return super(MyBaseAdmin, self).get_ordering(request)

Attachments (5)

ticket_12875.diff (2.0 KB ) - added by Manuel Saelices 15 years ago.
ticket_12875_for_r12454_with_tests.diff (4.3 KB ) - added by Manuel Saelices 15 years ago.
Patch with tests
ticket_12875_for_r16341.diff (5.0 KB ) - added by Manuel Saelices 13 years ago.
A new patch with tests for the [16341] version
ticket_12875_for_r16341_with_docs.diff (5.9 KB ) - added by Manuel Saelices 13 years ago.
ticket_12875_for_r16341_with_docs.2.diff (5.6 KB ) - added by Manuel Saelices 13 years ago.

Download all attachments as: .zip

Change History (13)

by Manuel Saelices, 15 years ago

Attachment: ticket_12875.diff added

comment:1 by Russell Keith-Magee, 15 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

by Manuel Saelices, 15 years ago

Patch with tests

comment:2 by Luke Plant, 14 years ago

Type: New feature

comment:3 by Luke Plant, 14 years ago

Severity: Normal

comment:4 by Manuel Saelices, 13 years ago

Easy pickings: unset
UI/UX: unset

The patch is not working in last Django trunk [16339]. I will work on it.

by Manuel Saelices, 13 years ago

A new patch with tests for the [16341] version

comment:5 by Ramiro Morales, 13 years ago

Needs documentation: set
Needs tests: unset

by Manuel Saelices, 13 years ago

comment:6 by Jannis Leidel, 13 years ago

Needs documentation: unset
Patch needs improvement: set

Looks good, except that the default get_ordering method should return self.ordering or () instead of checking all places.

by Manuel Saelices, 13 years ago

comment:7 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16383]:

Fixed #12875 -- Added get_ordering to ModelAdmin. Many thanks to Manuel Saelices.

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