The following warning appears in views.py:

UnorderedObjectListWarning: Pagination may yield the inconsistent results…

class UserListView(View) :
    "" user list view ""

    def get(self, request) :
        User List: - Receive parameter - Verify parameter - Query data - Paging
        user_queryset = User.objects.only('username'.'is_active'.'mobile'.'is_staff'.'is_superuser').order_by('id')
        groups = Group.objects.only('name').all()   
        query_dict = {}
        # check parameter
        Check whether the user is a superuser:
        groups__id = request.GET.get('group')
        if groups__id:
            try:
                groups__id = int(groups__id)
                query_dict['groups__id'] = groups__id
            except Exception as e:
                pass

        is_staff = request.GET.get('is_staff')
        if is_staff == '0':
            query_dict['is_staff'] = False
        if is_staff == '1':
            query_dict['is_staff'] = True

        is_superuser = request.GET.get('is_superuser')
        if is_superuser == '0':
            query_dict['is_superuser'] = False
        if is_superuser == '1':
            query_dict['is_superuser'] = True

        username = request.GET.get('username')

        if username:
            query_dict['username'] = username

        try:
            page = int(request.GET.get('page'.1))
        except Exception as e:
            page = 1

        paginater = Paginator(user_queryset.filter(**query_dict), 2)

        users = paginater.get_page(page)
        context = {
            'users': users,
            'groups': groups
        }
        context.update(query_dict)
        return render(request, 'myadmin/user/user_list.html', context=context)
Copy the code

Note: The code for this line in the above demonstration view is to sort the data when fetching it: User_queryset = user.objects. only(‘ username ‘, ‘is_active’, ‘mobile’, ‘is_staff’, ‘is_superuser’).order_by(‘ id ‘); order_by(‘ id ‘); Otherwise, the above warning would have appeared.