I have a generic list view from which I paginate using the querysets from two separate models : Message and safeTransaction.
django terminal output gives this warning upon entry to my inbox view :
/usr/local/lib/python3.6/dist-packages/django/views/generic/list.py:88: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: QuerySet. allow_empty_first_page=allow_empty_first_page, **kwargs)
This is the View and get_context_data method :
### Inbox list class
class InboxListView(ListView):
#This view lets the user view all the messages created in a list
model = Message
template_name = "myInbox/inbox.html"
paginate_by = 3 # paginating twice here
#so the page gets paginated in a convenient way for my template.
def get_context_data(self, **kwargs):
message_list = Message.objects.filter(recipient=self.request.user)
.order_by('-date')
safeTransaction_list = SafeTransaction.objects
.filter(trans_recipient=self.request.user)
.order_by('-date')
queryset = list(chain(message_list, safeTransaction_list))
#paginator setup start
paginator = Paginator(queryset,3)
page = self.request.GET.get('page')
safe_T_list = paginator.get_page(page) #iterable list for template
#paginator setup done
context = super(InboxListView, self).get_context_data(**kwargs)
context.update({
'now': timezone.now(),
'message_list':safe_T_list,
})
return context
What I am doing in this method is chaining the filtered querysets into a list, then paginating that as one queryset. The problem is that even before I do that, my filtered Messages and SafeTransactions are seen as unordered lists. This confuses me because the typical usage of order_by() on the django website is similar to what I have done.
In summary, I want to paginate using a queryset built from different object bases, but my filtered objects are consider unordered for reasons I don't understand.
stack trace :
Starting development server at http://127.0.0.1:4200/
Quit the server with CONTROL-C.
[17/Dec/2018 07:52:52] "GET / HTTP/1.1" 200 1490
[17/Dec/2018 07:52:52] "GET /static/css/mystyle.css HTTP/1.1" 200 1555
[17/Dec/2018 07:52:52] "GET /static/css/w3pro.css HTTP/1.1" 200 15672
[17/Dec/2018 07:52:52] "GET /static/css/w3.css HTTP/1.1" 200 23293
[17/Dec/2018 07:52:52] "GET /static/favicon.ico HTTP/1.1" 200 8192
/usr/local/lib/python3.6/dist-packages/django/views/generic/list.py:88: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'account.models.Message'> QuerySet.
allow_empty_first_page=allow_empty_first_page, **kwargs)
[17/Dec/2018 07:52:58] "GET /inbox HTTP/1.1" 200 3134
[17/Dec/2018 07:52:58] "GET /static/css/mystyle.css HTTP/1.1" 200 1555