Changes between Version 2 and Version 3 of Ticket #23662
- Timestamp:
- Oct 16, 2014, 4:09:37 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #23662 – Description
v2 v3 1 Current implementation: 2 https://github.com/django/django/blob/master/django/db/models/query.py 1 Current implementation: https://github.com/django/django/blob/master/django/db/models/query.py 3 2 4 3 {{{ … … 14 13 }}} 15 14 16 These methods call self._fetch_all(), thus evaluating the queryset. Although, this behaviour is documented (https://docs.djangoproject.com/en/1.7/ref/models/querysets/#when-querysets-are-evaluated), it is not obvious.15 These methods call `self._fetch_all()`, thus evaluating the queryset. Although, this behaviour is [https://docs.djangoproject.com/en/1.7/ref/models/querysets/#when-querysets-are-evaluated documented], it is not obvious. 17 16 18 It seems logical to evaluate queryset, when casting it to a list() or iterating over it, but these particular cases have nothing to do with the queryset contents. There exist specific lazy methods (QuerySet.exists() and QuerySet.count()respectively) which, IMHO, should be used for the magic method implementation.17 It seems logical to evaluate queryset, when casting it to a `list()` or iterating over it, but these particular cases have nothing to do with the queryset contents. There exist specific lazy methods (`QuerySet.exists()` and `QuerySet.count()` respectively) which, IMHO, should be used for the magic method implementation. 19 18 20 If I already have fetched the results of a queryset, I'm okay to call __len__() on them, but if they haven't been retrieved yet, I'd rather use SQL COUNT() instead. That is exactly, what QuerySet.count() does. The same goes for the __nonzero__() and exists().19 If I already have fetched the results of a queryset, I'm okay to call `__len__()` on them, but if they haven't been retrieved yet, I'd rather use `SQL COUNT()` instead. That is exactly, what QuerySet.count() does. The same goes for the `__nonzero__()` and `exists()`.