I have a simple model form:
class ProductSelectionForm(ModelForm):
class Meta:
model = Product
and the model:
class Product(models.Model):
name = models.CharField(max_length=155)
def __unicode__(self):
return self.name
But if I render the form using the {{ form.as_p }} tag it just renders the form as a single text input. How can I get the form to render as radio select options, with the name as the option label and the pk as the value? I have tried using widget but no joy.
Any help much appreciated.
You don’t want a modelform for that. They’re for creating and editing model instances. Instead, what you seem to want is a form to choose existing instances: for that, use a normal form with a ModelChoiceField: