Opened 8 years ago
Last modified 8 years ago
#28958 closed Bug
Using query expression in either the model's Meta.ordering or ModelAdmin.ordering causes an error — at Version 1
| 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 (last modified by )
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
Change History (1)
comment:1 by , 8 years ago
| Description: | modified (diff) | 
|---|---|
| Summary: | Using query expression in model Meta.ordering causes AttributeError in admin → Using query expression in either the model's Meta.ordering or ModelAdmin.ordering causes an error | 
  Note:
 See   TracTickets
 for help on using tickets.