UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list

created at 07-16-2021 views: 1

Django paging warning prompt

UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'xadmin.db.article.People'> QuerySet.

reason

Using the paging plugin that comes with django, you need to specify the field for sorting, and django does not specify the field sorting by default.

Original code:

class PeopleListView(ListView):

    context_object_name = 'objs'
    paginate_by = 100
    page_kwarg = 'page'
    status_kwarg = 'status'
    model = People

Solution

Specify ordering to execute ordering

class PeopleListView(ListView):

    context_object_name = 'objs'
    paginate_by = 100
    page_kwarg = 'page'
    status_kwarg = 'status'
    model = People
    ordering = ['id']
Please log in to leave a comment.