Opened 6 years ago

Closed 4 years ago

#12875 closed New feature (fixed)

Cannot redefine admin ordering dynamically

Reported by: msaelices 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 msaelices 6 years ago.
ticket_12875_for_r12454_with_tests.diff (4.3 KB) - added by msaelices 6 years ago.
Patch with tests
ticket_12875_for_r16341.diff (5.0 KB) - added by msaelices 4 years ago.
A new patch with tests for the [16341] version
ticket_12875_for_r16341_with_docs.diff (5.9 KB) - added by msaelices 4 years ago.
ticket_12875_for_r16341_with_docs.2.diff (5.6 KB) - added by msaelices 4 years ago.

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by msaelices

comment:1 Changed 6 years ago by russellm

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by msaelices

Patch with tests

comment:2 Changed 4 years ago by lukeplant

  • Type set to New feature

comment:3 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:4 Changed 4 years ago by msaelices

  • Easy pickings unset
  • UI/UX unset

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

Changed 4 years ago by msaelices

A new patch with tests for the [16341] version

comment:5 Changed 4 years ago by ramiro

  • Needs documentation set
  • Needs tests unset

Changed 4 years ago by msaelices

comment:6 Changed 4 years ago by jezdez

  • 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 4 years ago by msaelices

comment:7 Changed 4 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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