Opened 7 years ago

Closed 5 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 7 years ago.
ticket_12875_for_r12454_with_tests.diff (4.3 KB) - added by Manuel Saelices 7 years ago.
Patch with tests
ticket_12875_for_r16341.diff (5.0 KB) - added by Manuel Saelices 5 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 5 years ago.
ticket_12875_for_r16341_with_docs.2.diff (5.6 KB) - added by Manuel Saelices 5 years ago.

Download all attachments as: .zip

Change History (13)

Changed 7 years ago by Manuel Saelices

Attachment: ticket_12875.diff added

comment:1 Changed 7 years ago by Russell Keith-Magee

Has patch: set
Needs documentation: unset
Needs tests: set
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Changed 7 years ago by Manuel Saelices

Patch with tests

comment:2 Changed 5 years ago by Luke Plant

Type: New feature

comment:3 Changed 5 years ago by Luke Plant

Severity: Normal

comment:4 Changed 5 years ago by Manuel Saelices

Easy pickings: unset
UI/UX: unset

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

Changed 5 years ago by Manuel Saelices

A new patch with tests for the [16341] version

comment:5 Changed 5 years ago by Ramiro Morales

Needs documentation: set
Needs tests: unset

Changed 5 years ago by Manuel Saelices

comment:6 Changed 5 years ago by Jannis Leidel

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.

Changed 5 years ago by Manuel Saelices

comment:7 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:8 Changed 5 years ago by Jannis Leidel

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