Opened 5 years ago

Closed 5 years ago

#30804 closed Cleanup/optimization (invalid)

Minor issue in Chaining filters section in given example code

Reported by: ArjunAriyil Owned by: nobody
Component: Documentation Version: 2.2
Severity: Normal Keywords: Chaining filters
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

https://docs.djangoproject.com/en/2.2/topics/db/queries/

In the Chaining filters section, "pub_date__gte=datetime.date.today()" needs to be replaced with "pub_date__lte=datetime.date.today() to get entries published between January 30, 2005, and the current day.


Chaining filters

The result of refining a QuerySet is itself a QuerySet, so it’s possible to chain refinements together. For example:

>>> Entry.objects.filter(
...     headline__startswith='What'
... ).exclude(
...     pub_date__gte=datetime.date.today()
... ).filter(
...     pub_date__gte=datetime.date(2005, 1, 30)
... )

This takes the initial QuerySet of all entries in the database, adds a filter, then an exclusion, then another filter. The final result is a QuerySet containing all entries with a headline that starts with “What”, that were published between January 30, 2005, and the current day.

Change History (2)

comment:1 by Nicolas Pantel, 5 years ago

There is no issue.
The first filter excludes entries published after today, then the second keep entries published after January 30, 2005.
The result are the entries published between January 30, 2005 and today, as stated.

comment:2 by Nicolas Pantel, 5 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top