Saturday, 7 September 2013

Don't understand "id" property in Django tutorial

Don't understand "id" property in Django tutorial

I have the following code from the Django tutorial:
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}"
value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text
}}</label><br />
{% endfor %}
And there is something I don't understand.
The value of the id property of input is choice{{ forloop.counter }}. So,
it will be something like this: choice1, choice2 etc...
And in the views.py I have the following line:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
But pk must be a number. How it works here?

No comments:

Post a Comment