"Don’t use len() on QuerySets" is too strong.
I've seen people write code like:
qs = Model.objects.filter(a=b)
if qs.count() >= 1:
for q in qs:
# do something with q
They think the that ".count()" call is more efficient, but it actually makes it slower. I asked the person about it they said: "the docs say don't use len() on querysets".
Patch needs improvement: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
https://github.com/django/django/pull/3961