Opened 3 years ago

Last modified 3 years ago

#32554 closed New feature

Add Q.TRUE, Q.FALSE, Q.any() and Q.all() — at Version 1

Reported by: jonathan-golorry Owned by: jonathan-golorry
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 (last modified by jonathan-golorry)

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.

Change History (1)

comment:1 by jonathan-golorry, 3 years ago

Description: modified (diff)
Has patch: set
Needs documentation: set
Owner: changed from nobody to jonathan-golorry
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top