text: Opened 5 years ago
  Closed 5 years ago
  Last modified 5 years ago
  #14052 closed (invalid)
  Error on a code in Tutorial 01
  Description
  I'm learning Python and Django, and in tutorial 01, on url, I think the code that's adding a custom method in the Poll class is wrong. Where is written:
  import datetime # ... class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.date.today()
  should be:
  import datetime # ... class Poll(models.Model): # ... def was_published_today(self): return self.pub_date.date() == datetime.today().date()
  The error is in the order today date invocation.
  Sorry for my poor english, I'm brazillian.
  Change History (2)
  comment:1 Changed 5 years ago by kmtracey
  - Needs documentation unset
  - Needs tests unset
  - Patch needs improvement unset
  - Resolution set to invalid
  - Status changed from new to closed
  comment:2 Changed 5 years ago by wagnerluis1982
  Sorry for annoy by this ticket. The tutorial code is right, but with me didn't work because I was using Eclipse to edit the code and the autocompletion of datetime added incorrectly the import
  from django.utils.datetime_safe import datetime
  that uses datetime instance
  The tutorial code is correct. Try it in a Python shell:
  The proposed change does not work:
  Using the today() constructor of the datetime.datetime class instead of trying it on the datetime module (yes, this is a bit confusing in Python) would work:
  But the existing code is simpler and works, so is preferable.