#14873: A paginated ListView with a List instead of queryset produces an error
---------------------------+------------------------------------------------
Reporter: andornaut | Owner: nobody
Status: new | Milestone:
Component: Generic views | Version: 1.3-alpha
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
== Background ==
This issue occurs when using a subclass of `ListView` that overrides the
`get_queryset` method and returns a `List` instead of a `queryset`, while
also defining `paginage_by`. This should work according to the docstring
for `get_queryset`, but it produces an exception.
== Relevant Code ==
django.views.generic.list.!MultipleObjectMixin.get_queryset!#15
{{{
#!python
def get_queryset(self):
"""
Get the list of items for this view. This must be an interable,
and may
be a queryset (in which qs-specific behavior will be enabled).
}}}
django.views.generic.list.!MultipleObjectMixin.paginate_queryset!#31
{{{
#!python
def paginate_queryset(self, queryset, page_size):
"""
Paginate the queryset, if needed.
"""
if queryset.count() > page_size:
}}}
The error occurs when trying to evaluate `queryset.count()` on a List.
== Possible Solution ==
If a non-queryset Iterable is used, then use `len(queryset)` instead of
`queryset.count()`
--
Ticket URL: <http://code.djangoproject.com/ticket/14873>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.