#9564 closed (invalid)
datetime function used incorrectly in "Writing your first app" part 1
Reported by: | delaney | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the second to last code block of Part 1
import datetime # ... class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.date.today()
should be...
from datetime import datetime # ... class Poll(models.Model): # ... def was_published_today(self): return self.pub_date == datetime.today()
Otherwise you get the following error
Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\eclipse\workspace\mysite\..\mysite\polls\models.py", line 12, in was_ published_today return self.pub_date.date() == date.today() AttributeError: 'datetime.date' object has no attribute 'date'
Note:
See TracTickets
for help on using tickets.
The line of code you show in the error does not match either of the code blocks you show higher up?
The existing example is correct, really, if you follow it exactly.