#28958: Using query expression in model Meta.ordering causes AttributeError in
admin
-------------------------------------+-------------------------------------
               Reporter:  Gabriel    |          Owner:  nobody
  Amram                              |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  2.0
  contrib.admin                      |       Keywords:  query expresssion,
               Severity:  Normal     |  ordering, admin, meta
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28958>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.b76b1ea634f2f35522057fd132b12cb3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to