Opened 17 years ago

Closed 17 years ago

#5059 closed (duplicate)

Probably missing import in sample code

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

On the page:
http://www.djangoproject.com/documentation/tutorial01/

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.

Poll.objects.all()

[]

# Create a new Poll.

from datetime import datetime
p = Poll(question="What's up?", pub_date=datetime.now())

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

p.save()

# 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.

p.id

1

# Access database columns via Python attributes.

p.question

"What's up?"

p.pub_date

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)
p.save()

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

Poll.objects.all()

[<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?", pub_date=datetime.now())

Change History (5)

comment:1 by Simon G. <dev@…>, 17 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #4941.

comment:2 by anonymous, 17 years ago

Resolution: duplicate
Status: closedreopened

comment:3 by anonymous, 17 years ago

Resolution: fixed
Status: reopenedclosed

comment:4 by Simon G. <dev@…>, 17 years ago

Resolution: fixed
Status: closedreopened

Undoing spam-bot twiddling

comment:5 by Simon G. <dev@…>, 17 years ago

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