Reputation: 38910
I have the following code in Django for a Form.
class ProductAddToCartForm(forms.Form):
quantity = forms.IntegerField(widget=forms.TextInput(attrs={'size':'2', 'value':'1', 'class':'quantity', 'maxlength':'5'}), error_messages={'invalid':'Please enter a valid quantity.'}, min_value =1)
product_slug = forms.CharField(widget=forms.HiddenInput())
sizes_available = []
sizes_available.append(7)
sizes_available.append(9)
size = forms.ChoiceField(widget=forms.Select, choices=sizes_available)
However when I compile this the ChoiceField
, CharField
and the IntegerField
doesn't show up. When I comment out the line with size = ...
then IntegerField
and CharField
shows up. I think there is something wrong with my ChoiceField
declaration but I'm not sure what exactly.
Upvotes: 0
Views: 167
Reputation: 6756
https://docs.djangoproject.com/en/1.4/ref/forms/fields/#choicefield
Choices must be
An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this field.
Try to .append((7,7))
Upvotes: 4