Python Django Rest Framework UnorderedObjectListWarning

前端 未结 7 2199
时光取名叫无心
时光取名叫无心 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:16

    So in order to fix this I had to find all of the all, offset, filter, and limit clauses and add a order_by clause to them. Some I fixed by adding a default ordering:

    class Meta:
       ordering = ['-id']
    

    In the ViewSets for Django Rest Framework (app/apiviews.py) I had to update all of the get_queryset methods as adding a default ordering didn't seem to work.

    Hope this helps someone else. :)

提交回复
热议问题