Opened 5 years ago

Closed 5 years ago

#28177 closed Cleanup/optimization (duplicate)

Clarify documentation with regards to Q objects and OR

Reported by: Yoong Kang Lim Owned by: Yoong Kang Lim
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In the QuerySet documentation it is written:

In general, Q() objects make it possible to define and reuse conditions. This permits the construction of complex database queries using |
(OR) and & (AND) operators; in particular, it is not otherwise possible to use OR in QuerySets.

It's possible to use OR without Q objects by simply using the | operator on two querysets, e.g:

queryset = Article.objects.filter(headline__startswith='Hello') | Article.objects.filter(headline__startswith='Goodbye')

Examples of this still remain in in the or_lookups tests, although I must confess I haven't used this style much.

Perhaps the wording should be changed, or simply removed.

Change History (2)

comment:1 Changed 5 years ago by Yoong Kang Lim

Owner: changed from nobody to Yoong Kang Lim
Status: newassigned

comment:2 Changed 5 years ago by Tim Graham

Resolution: duplicate
Status: assignedclosed
Type: UncategorizedCleanup/optimization

Duplicate of #21333

Note: See TracTickets for help on using tickets.
Back to Top