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 | }) |