Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions fuzzycount.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from distutils.version import LooseVersion

from django.conf import settings
from django.db import connections
from django.db.models import QuerySet, Manager
import django


DJANGO_VERSION_GTE_19 = LooseVersion(django.get_version()) \
>= LooseVersion('1.9')


class FuzzyCountQuerySet(QuerySet):
Expand All @@ -16,15 +9,7 @@ def count(self):
engine = settings.DATABASES[self.db]["ENGINE"].split(".")[-1]
is_postgres = engine.startswith(postgres_engines)

# In Django 1.9 the query.having property was removed and the
# query.where property will be truthy if either where or having
# clauses are present. In earlier versions these were two separate
# properties query.where and query.having
if DJANGO_VERSION_GTE_19:
is_filtered = self.query.where
else:
is_filtered = self.query.where or self.query.having
if not is_postgres or is_filtered:
if not is_postgres or self.query.where:
return super(FuzzyCountQuerySet, self).count()
cursor = connections[self.db].cursor()
cursor.execute("SELECT reltuples FROM pg_class "
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
py_modules=["fuzzycount",],
install_requires = [
"sphinx-me >= 0.1.2",
"django >= 1.7",
"django >= 1.9",
],
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down