(self)
| 38 | """ |
| 39 | |
| 40 | def count(self): |
| 41 | if self.query.where: |
| 42 | return super(ApproximateCountQuerySet, self).count() |
| 43 | |
| 44 | if is_postgres_db() and not settings.TESTING: |
| 45 | cursor = connections[self.db].cursor() |
| 46 | cursor.execute( |
| 47 | "SELECT reltuples FROM pg_class WHERE relname = '%s';" % self.model._meta.db_table |
| 48 | ) |
| 49 | |
| 50 | return int(cursor.fetchone()[0]) |
| 51 | |
| 52 | return super(ApproximateCountQuerySet, self).count() |
| 53 | |
| 54 | |
| 55 | ApproximateCountManager = Manager.from_queryset(ApproximateCountQuerySet) |