#31994 closed Bug (invalid)
Error in Tutorial 2 — at Version 1
Reported by: | Agorar101 | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 3.1 |
Severity: | Normal | Keywords: | Tutorial 2, TypeError |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The following function produces an error in the Tutorial 2. It can be problematic for new users that are getting acquainted with Django and do not know how to fix this issue.
class Question(models.Model): # ... def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
returns the following error:
TypeError: can't compare datetime.datetime to datetime.date
It is easily fixed invoking the date method from now in the following way.
class Question(models.Model): # ... def was_published_recently(self): return self.pub_date >= timezone.now().date() - datetime.timedelta(days=1)
Change History (1)
comment:1 by , 4 years ago
Component: | Uncategorized → Documentation |
---|---|
Description: | modified (diff) |
Resolution: | → invalid |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
You've probably made a mistake somewhere, because
pub_date
is aDateTimeField
so tutorial works properly. Closing per TicketClosingReasons/UseSupportChannels.