Changes between Initial Version and Version 1 of Ticket #31994


Ignore:
Timestamp:
Sep 10, 2020, 9:29:14 AM (4 years ago)
Author:
Mariusz Felisiak
Comment:

You've probably made a mistake somewhere, because pub_date is a DateTimeField so tutorial works properly. Closing per TicketClosingReasons/UseSupportChannels.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31994

    • Property Component UncategorizedDocumentation
    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #31994 – Description

    initial v1  
    11The 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.
    2 
     2{{{
    33class Question(models.Model):
    44    # ...
    55    def was_published_recently(self):
    66        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
    7 
     7}}}
    88returns the following error:
    99
     
    1111
    1212It is easily fixed invoking the date method from now in the following way.
    13 
     13{{{
    1414class Question(models.Model):
    1515    # ...
    1616    def was_published_recently(self):
    1717        return self.pub_date >= timezone.now().date() - datetime.timedelta(days=1)
     18}}}
Back to Top