I have a foreign key reference which shows up as a select box on the client but it is pre-populated with values. I want the select box to be empty when it shows because it will be populated by an Ajax call.
This is my model
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe)
ingredient = models.ForeignKey(Ingredient)
serving_size = models.ForeignKey(ServingSize)
quantity = models.IntegerField()
order = models.IntegerField()
created = models.DateTimeField(auto_now_add = True)
updated = models.DateTimeField(auto_now = True)
and this is my model form
class RecipeIngredientForm(forms.ModelForm):
class Meta:
model = RecipeIngredient
fields = ('ingredient', 'quantity', 'serving_size')
widgets = {
'ingredient': forms.TextInput(attrs={'class' : 'recipe_ingredient'}),
'quantity': forms.TextInput(),
'serving_size' : forms.ChoiceField(choices=PLEASE_SELECT, widget=forms.Select()),
}
I want the "serving_size" field to have the choices I specified and not any data from the database. Obviously, I get an error
AttributeError: 'ModelChoiceField' object has no attribute 'to_field_name'
Any ideas?