Opened 9 years ago

Closed 9 years ago

#5059 closed (duplicate)

Probably missing import in sample code

Reported by: gregg Owned by: Jacob
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:


On the page:

There is a sample code:
# Import the model classes we just wrote.

from mysite.polls.models import Poll, Choice

# No polls are in the system yet.



# Create a new Poll.

from datetime import datetime
p = Poll(question="What's up?",

# Save the object into the database. You have to call save() explicitly.

# Now it has an ID. Note that this might say "1L" instead of "1", depending
# on which database you're using. That's no biggie; it just means your
# database backend prefers to return integers as Python long integer
# objects.


# Access database columns via Python attributes.


"What's up?"


datetime.datetime(2005, 7, 15, 12, 00, 53)

# Change values by changing the attributes, then calling save().

p.pub_date = datetime(2005, 4, 1, 0, 0)

# objects.all() displays all the polls in the database.


[<Poll: Poll object>]

which throws:
Traceback (most recent call last):

File "<console>", line 1, in <module>

NameError: name 'datetime' is not defined

after this line:

p = Poll(question="What's up?",

Change History (5)

comment:1 Changed 9 years ago by Simon G. <dev@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

Duplicate of #4941.

comment:2 Changed 9 years ago by anonymous

Resolution: duplicate
Status: closedreopened

comment:3 Changed 9 years ago by anonymous

Resolution: fixed
Status: reopenedclosed

comment:4 Changed 9 years ago by Simon G. <dev@…>

Resolution: fixed
Status: closedreopened

Undoing spam-bot twiddling

comment:5 Changed 9 years ago by Simon G. <dev@…>

Resolution: duplicate
Status: reopenedclosed
Note: See TracTickets for help on using tickets.
Back to Top