Opened 7 years ago
Last modified 7 years ago
#28958 closed Bug
Using query expression in model Meta.ordering causes AttributeError in admin — at Initial Version
Reported by: | Gabriel Amram | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 2.0 |
Severity: | Release blocker | Keywords: | query expresssion, ordering, admin, meta |
Cc: | Mariusz Felisiak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using the newly introduced query-expression ordering feature in either the model's Meta.ordering or in its ModelAdmin causes errors.
Steps to reproduce:
First variant - using the model's Meta.ordering option -
//models.py class Game(models.Model): score = models.IntegerField(null=True) class Meta: ordering = [F("score").desc(nulls_last=True)] ... // admin.py admin.site.register(Game)
Accessing the admin site will now give an AttributeError: 'OrderBy' object has no attribute 'startswith'
Variant 2 - Using the ModelAdmin ordering attribute:
//admin.py class GameAdmin(models.ModelAdmin): ordering = [F("score").desc(nulls_last=True)]
runserver
fails with error: TypeError: argument of type 'OrderBy' is not iterable
Note:
See TracTickets
for help on using tickets.