Ticket #6899: nonzero-queryset-2.diff
File nonzero-queryset-2.diff, 1.3 KB (added by , 17 years ago) |
---|
-
django/db/models/query.py
72 72 iter(self).next() 73 73 except StopIteration: 74 74 return False 75 return True 75 else: 76 return True 77 return bool(self._result_cache) 76 78 77 79 def __getitem__(self, k): 78 80 "Retrieve an item or slice from the set of results." -
tests/modeltests/nonzero/models.py
1 """ 2 43. Boolean evaluation of QuerySets 3 4 This tests that QuerySet.__nonzero__ behaves consistently between caching. 5 """ 6 7 from django.db import models 8 9 class Empty(models.Model): 10 pass 11 12 __test__ = {'API_TESTS':""" 13 >>> objects = Empty.objects.all() 14 >>> bool(objects) 15 False 16 >>> bool(objects) 17 False 18 >>> Empty().save() 19 >>> bool(Empty.objects.filter(pk=1).extra(select={'a':1}).values('a')) 20 True 21 """}