Python Django Rest Framework UnorderedObjectListWarning

前端 未结 7 2113
时光取名叫无心
时光取名叫无心 2021-01-30 15:47

I upgraded from Django 1.10.4 to 1.11.1 and all of a sudden I\'m getting a ton of these messages when I run my tests:

lib/python3.5/site-packages/rest_framework/         


        
7条回答
  •  迷失自我
    2021-01-30 16:18

    Update the model meta class instead.

    class UsefulModel(models.Model):
        
        class Meta:
            ordering='-created' # for example
    

    you can still override the ordering from the view attribute 'ordering' As advised by AlanSE previously.

    class UsefulView(ListView):
        ordering = ['-created']
    

提交回复
热议问题