#32554: Add Q.TRUE, Q.FALSE, Q.any() and Q.all()
-------------------------------------+-------------------------------------
     Reporter:  jonathan-golorry     |                    Owner:  jonathan-
                                     |  golorry
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  Q objects, any, all  |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by jonathan-golorry:

Old 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).
>
> Patch: https://github.com/django/django/pull/14131
>
> 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.

New description:

 `Q.empty()` checks for nested empty Q objects such as `Q(Q())`. See #32549
 for rationale.

 `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).

 Patch: https://github.com/django/django/pull/14159

 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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32554#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/074.187dbfd81a0db8f80f6dcb923199dd80%40djangoproject.com.

Reply via email to