Opened 16 years ago

Closed 16 years ago

Last modified 15 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: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 by Karen Tracey, 16 years ago

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 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

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