Skip to content Skip to sidebar Skip to footer

Typeerror: 'choice_text' Is An Invalid Keyword Argument For This Function In Django Tutorial

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 a

Solution 1:

Are you sure you are copying directly from the tutorial. It looks like it is choice= instead of choice_text=

# Create three choices.
>>>p.choice_set.create(choice='Not much', votes=0)
<Choice: Not much>
>>>p.choice_set.create(choice='The sky', votes=0)
<Choice: The sky>

The model is:

classChoice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

So what this line is doing is by using choice_set.create() (link to docs), it's creating a Choice model and taking the poll - p - and assigning that as the model field poll (the foreign key). And then assigning the choice= value to the model field choice, and the votes= value to the model field votes.

Post a Comment for "Typeerror: 'choice_text' Is An Invalid Keyword Argument For This Function In Django Tutorial"