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 , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
comment:3 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:5 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Duplicate of #4941.