Jeremy Dunck wrote: > I just ran into the same issue several people before me have: > Paginator is a bit dangerous when handed a queryset, and > QuerySetPaginator should be used instead. > > This ticket exists, but no core dev has contributed to discussion yet. > http://code.djangoproject.com/ticket/7478 > > I'd like to avoid making it dangerously easy to consume memory/cpu on > the full queryset. > > isinstance(object_list, QuerySet) is a fairly straightforward way to > collapse Paginator and QuerySetPaginator into a single class. > > Are we not doing that because it'd mean importing django.db into a > django.core object? > > Is there some other way we can point the gun away from our foot?
I, for one, would be in favor of doing away with QueryPaginator and bringing back the behaviour of the _get_count() method of the lecacy ObjectPaginator: def _get_count(self): # The old API allowed for self.object_list to be either a QuerySet or a # list. Here, we handle both. if self._count is None: try: self._count = self.object_list.count() except TypeError: self._count = len(self.object_list) return self._count count = property(_get_count) The legacy _get_count first tries to do object_list.count() with no arguments. That raises a TypeError if object_list is a list, since list.count() requires an argument. If the TypeError is raised, then _get_count falls back to using len(object_list). Seems like this is a nice interface, either have your object_list provide a count() method or rely on len(object_list). I believe this sort of duck typing would be better than an explicit type check. Then, we would have no dangers when passing a QuerySet, no confusion as to which Paginator class to use, and the ability to accept any other "object_list" instance that has a count() method or can have len() called on it. Gary --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---