Python Django Rest Framework UnorderedObjectListWarning
In my case, I had to add order_by('id')
instead of ordering
.
class IntakeCaseViewSet(viewsets.ModelViewSet):
schema = None
queryset = IntakeCase.objects.all().order_by('id')
Ordering
needs to be in the model using Class Meta (not View).
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. :)
I was getting this warning when i used objects.all() in my view.py
profile_list = Profile.objects.all()
paginator = Paginator(profile_list, 25)
to fix this i changed my code to :
profile_list = Profile.objects.get_queryset().order_by('id')
paginator = Paginator(profile_list, 25)