Python Django Rest Framework UnorderedObjectListWarning

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

    Including this didn't work for me.

    class Meta:
       ordering = ['-id']
    

    But changing get_queryset(self) and sorting the list with .order_by('id') did. Maybe worked because I'm using filters, I don't know

    class MyView(viewsets.ModelViewSet):
        queryset = MyModel.objects.all()
        serializer_class = MySerializerSerializer
    
        def get_queryset(self):
            user = self.request.user
            return MyModel.objects.filter(owner=user).order_by('id')
    

提交回复
热议问题