Why do I get the following error in my app
Caught TypeError while rendering: 'ModelNameHere' object is not iterable
but I don't get it when I execute it from the s开发者_如何学JAVAhell?
I just have a custom field in my form which inherits from forms.ModelForm
custom_serving_size = forms.ChoiceField(
ServingSize.objects.all(),
widget=forms.Select(attrs={'class':'ddl'})
)
EDIT
This is my form class
class RecipeIngredientForm(forms.ModelForm):
serving_size = forms.ChoiceField(choices=ServingSize.objects.all())
The error happens on ServingSize.objects.all()
custom_serving_size = forms.ChoiceField(
ServingSize.objects.all(),
widget=forms.Select(attrs={'class':'ddl'})
)
this has to be
custom_serving_size = forms.ModelChoiceField(
queryset=ServingSize.objects.all(),
widget=forms.Select(attrs={'class':'ddl'})
)
or
custom_serving_size = forms.ChoiceField(
choices=[(obj.id, `text user sees`) for obj in ServingSize.objects.all()],
widget=forms.Select(attrs={'class':'ddl'})
)
精彩评论