Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9564 closed (invalid)

datetime function used incorrectly in "Writing your first app" part 1

Reported by: delaney Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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'

Change History (2)

comment:1 Changed 8 years ago by Karen Tracey

Resolution: invalid
Status: newclosed

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.

comment:2 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

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