Opened 5 years ago
Last modified 5 years ago
#32554 closed New feature
Add Q.TRUE, Q.FALSE, Q.any() and Q.all() — at Initial Version
| Reported by: | jonathan-golorry | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | Q objects, any, all |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Q.FALSE and Q.TRUE are classattribute aliases for Q(pk__in=[]) and ~Q(pk__in=[]).
Q.any() and Q.all() mimic python's builtin any and all, defaulting to Q.FALSE and Q.TRUE for empty iterators (or iterators containing only empty Q objects).
See this forum thread discussing why these are an improvement over many ad-hoc implementations people are using: https://forum.djangoproject.com/t/improving-q-objects-with-true-false-and-none/851
My patch relies on https://code.djangoproject.com/ticket/32548 and https://code.djangoproject.com/ticket/32549. I kept those as separate tickets because they each had side effects that warranted their own discussion.