Django ModelForm for Many-to-Many fields

Posted by theycallmemorty on Stack Overflow See other posts from Stack Overflow or by theycallmemorty
Published on 2010-02-07T13:59:48Z Indexed on 2010/04/23 19:33 UTC
Read the original article Hit count: 527

Consider the following models and form:

class Pizza(models.Model):
    name = models.CharField(max_length=50)

class Topping(models.Model):
    name = models.CharField(max_length=50)
    ison = models.ManyToManyField(Pizza, blank=True)

class ToppingForm(forms.ModelForm):
    class Meta:
        model = Topping

When you view the ToppingForm it lets you choose what pizzas the toppings go on and everything is just dandy.

My questions is: How do I define a ModelForm for Pizza that lets me take advantage of the Many-to-Many relationship between Pizza and Topping and lets me choose what Toppings go on the Pizza?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-modelforms