I have an Item object that has a manytomany relation to another object Option. I create a modelform from the Item object like so;
class Item(models.Model):
category = models.ForeignKey(Category)
name = models.CharField(max_length=200)
price = models.DecimalField(max_digits=9, decimal_places=2, blank=True, null=True)
options = models.ManyToManyField(Option)
class OptionForm(ModelForm):
options = forms.ChoiceField(widget=forms.RadioSelect())
class Meta:
model = Item
fields = ( 'options', )
When i render the form in the template it renders all available options
for the Item
object(the expected behavior) even those not created by a specific item. I want to be able to load options
defined by the specific Item that will be chosen by the user. How do i override the form to achieve such behavior.for example without a form i can render an Items
own Options
through its id. item = Item.objects.get(pk=id)