Is it possible to create a single-page “Order form” for 1:M:N model?
name = models.CharField(max_length=100)
type = models.CharField(max_length=100)
amount = models.FloatField(validators=[MinValueValidator(0.1), MaxValueValidator(9999.0)])
box_label = models.CharField(max_length=100)
box_type = models.PositiveSmallIntegerField(validators=[MinValueValidator(1), MaxValueValidator(999)])
toppings = models.ManyToManyField(Topping,blank=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
code = models.CharField(max_length=100)
pizzas = models.ManyToManyField(Pizza, blank=True)
One “quick-and-dirty” solution is submit it as “plain HTML form” and handle POST parameters manually - without “django-form” features like validations, automatic binding, etc, but I would like to use django’s form features which are very handy.
[Side note: I’m curious about the use of ManyToMany fields here, typically, this type of data structure is represented by a ForeignKey in Pizza to Order, and a ForeignKey in Topping to Pizza.]
Hi, nested formsets looked too complicated. I solved this problem with custom form objects, which were not as complicated as I thought (couple of boilerplate code for request parameters binding but OK).
To your question about ManyToMany fields: I am Django newbie, so I thought using this relationship I can easily access “master-detail” values. Now I know, Django provides “something_set” collection on master object for details objects in OneToMany relationship, what was exactly what I was looking for.
Now, I finished this simple project and I can say, Django is really very interesting and powerful framework for rapid web app development.