Opened 8 years ago

Closed 8 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:

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 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #4941.

comment:2 Changed 8 years ago by anonymous

  • Resolution duplicate deleted
  • Status changed from closed to reopened

comment:3 Changed 8 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

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

  • Resolution fixed deleted
  • Status changed from closed to reopened

Undoing spam-bot twiddling

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

  • Resolution set to duplicate
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.
Back to Top