Opened 4 years ago

Last modified 4 years ago

#31994 closed Bug

Error in Tutorial 2 — at Initial Version

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

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 (0)

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