Skip to content

Commit

Permalink
add PaginatedRawQuerySet.count for better Django compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
knipknap committed Nov 25, 2018
1 parent 60256f6 commit e90e8ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django_find/rawquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ def __len__(self):
row = cursor.fetchone()
self.count_cache = int(row[0])
return self.count_cache

count = property(__len__) # For better compatibility to Django's QuerySet
8 changes: 8 additions & 0 deletions tests/test_rawquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ def testLen(self):
self.assertEqual(len(self.query[:8]), 8)
self.assertEqual(len(self.query[:]), 10)
self.assertEqual(len(self.query[1:]), 9)

def testCount(self):
self.assertEqual(self.query.count, 10)
self.assertEqual(self.query.count, 10) # Cached
self.assertEqual(self.query[2:8].count, 6)
self.assertEqual(self.query[:8].count, 8)
self.assertEqual(self.query[:].count, 10)
self.assertEqual(self.query[1:].count, 9)

0 comments on commit e90e8ff

Please sign in to comment.