This is probably a feature that has been proposed before, but I could
not find a discussion on it, so I proposed it on the tracker, and Tim
also couldn't find a discussion.
(ticket: https://code.djangoproject.com/ticket/30118 )
I would like to propose being able to write
`SomeModel.objects.filter(field=value).exists()` (and similar for
As Tim rightfully commented: "There should be one-- and preferably only
one --obvious way to do it.".
I'm proposing this is a case where the obvious way would eventually be
more in line with my suggestion instead of what we currently use.
Consider the following code example (from
There is a weird (to me, your mileage might vary) ").exists()" as a
final line, and I would like to write this as
This pattern seems to be quite rare in the Django codebase itself, but
in the codebase at work we have several cases of `queryset.filter(<lots
of lines>).exists()` (and similar with count), and I am expecting this
to also be prevalent in other codebases out there.
Arguing against it however are the following lines of the Zen of Python:
- "Explicit is better than implicit."
- Maybe also "Special cases aren't special enough to break the rules.",
because `.filter().count()` and `.exclude().count()` are both the same
pattern, but this would only create an alternative for the first.
- "There should be one-- and preferably only one --obvious way to do it."
Beyond these short quips, I was hoping there might also be an earlier
discussion covering this.
Sjoerd Job Postmus
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
For more options, visit https://groups.google.com/d/optout.