I’m working through https://docs.djangoproject.com/en/1.4/intro/tutorial01/ .
Towards the end of the tutorial is a section on the django DB api there is the following:
# Display any choices from the related object set -- none so far.
>>> p.choice_set.all()
[]
# Create three choices.
>>> p.choice_set.create(choice_text='Not much', votes=0)
<Choice: Not much>
However when I directly copy : >>> p.choice_set.create(choice_text=’Not much’, votes=0) from the tutorial, I get:
raise TypeError("'%s' is an invalid keyword argument for this function" % kw
args.keys()[0])
TypeError: 'choice_text' is an invalid keyword argument for this function
previously everything in the tut worked as expected.
Any idea what the problem is ? I’m pretty new to python coming from a php background with some OOP experience.
Thanks in advance,
Bill
Are you sure you are copying directly from the tutorial. It looks like it is
choice=instead ofchoice_text=The model is:
So what this line is doing is by using
choice_set.create()(link to docs), it’s creating aChoicemodel and taking the poll –p– and assigning that as the model fieldpoll(the foreign key). And then assigning thechoice=value to the model fieldchoice, and thevotes=value to the model fieldvotes.