Ticket #18087: 18087.patch

File 18087.patch, 1.0 KB (added by Aymeric Augustin, 12 years ago)
  • django/views/generic/dates.py

     
    194194        if not allow_future:
    195195            qs = qs.filter(**{'%s__lte' % date_field: timezone.now()})
    196196
    197         if not allow_empty and not qs:
    198             raise Http404(_(u"No %(verbose_name_plural)s available") % {
    199                     'verbose_name_plural': force_unicode(qs.model._meta.verbose_name_plural)
    200             })
     197        if not allow_empty:
     198            # When pagination is enabled, it's better to do a cheap query
     199            # than to load the unpaginated queryset in memory.
     200            is_empty = not bool(qs) if paginate_by is None else not qs.exists()
     201            if is_empty:
     202                raise Http404(_(u"No %(verbose_name_plural)s available") % {
     203                        'verbose_name_plural': force_unicode(qs.model._meta.verbose_name_plural)
     204                })
    201205
    202206        return qs
    203207
Back to Top