Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7546 closed (fixed)

Exact lookups on DateTimeField() with datetime.date object does not work

Reported by: john_scott Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In http://www.djangoproject.com/documentation/db-api/ there are several examples of passing in datetime.date() objects (notice it's not a datetime.datetime() object) as lookup parameters on a DateTimeField(). See http://www.djangoproject.com/documentation/db-api/#spanning-multi-valued-relationships for one such example:

Blog.objects.filter(entry__headline__contains='Lennon',
        entry__pub_date=datetime.date.today())

The only way I've been able to get the intended behavior is through the use of the range lookup:

today = datetime.date(2008, 6, 26)
tomorrow = datetime.date(2005, 6, 27)
Blog.objects.filter(entry__headline__contains='Lennon', 
        entry__pub_date__range=(today, tomorrow))

I'm assuming this is just a documentation issue, rather than a query bug.

Attachments (1)

7546.diff (1.7 KB) - added by dcwatson 6 years ago.
doc update

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by garcia_marc

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by dcwatson

  • Has patch set

Speaking to the author of this documentation (Malcolm wishes to remain nameless), this is indeed a documentation bug. Patch to follow.

Changed 6 years ago by dcwatson

doc update

comment:3 Changed 6 years ago by anonymous

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [8232]) Fixed #7546 -- Fixed an incorrect example in the docs that was misleading some
people. Patch from Dan Watson.

comment:5 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.