Opened 18 years ago

Closed 18 years ago

#2352 closed enhancement (duplicate)

Allow Paginator to Support Non QuerySets

Reported by: germish@… Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: normal Keywords: paginator queryset fetchall
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I write quite a few Custom SQL queries. In addition, I like the built in paginator package that django provides. The problem is that paginator.py asks for a QuerySet, when all it uses a QuerySet for is to query_set.count(). Anyways, my point is... paginator.py should allow for queries returned by cursor.fetchall() (and similar). It's already so generic that this tiny patch provides this enhancement:

/django/core/paginator.py

def _get_hits(self):
    if self._hits is None:
        try:
            self._hits = self.query_set.count()
        except:
            self._hits = len(self.query_set)
    return self._hits

All I added was the try-except block to default to len(self.query_set) if .count() fails

Change History (2)

comment:1 by Chris Beaven, 18 years ago

My patch in #2093 fixes this and more! :)

It is still waiting to be applied (or at least critiqued).

comment:2 by Adrian Holovaty, 18 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #2093.

Note: See TracTickets for help on using tickets.
Back to Top