Inline editing of ManyToMany relation in Django
- by vorpyg
After working through the Django tutorial I'm now trying to build a very simple invoicing application.
I want to add several Products to an Invoice, and to specify the quantity of each product in the Invoice form in the Django admin. Now I've to create a new Product object if I've got different quantites of the same Product.
Right now my models look like this (Company and Customer models left out):
class Product(models.Model):
description = models.TextField()
quantity = models.IntegerField()
price = models.DecimalField(max_digits=10,decimal_places=2)
tax = models.ForeignKey(Tax)
class Invoice(models.Model):
company = models.ForeignKey(Company)
customer = models.ForeignKey(Customer)
products = models.ManyToManyField(Product)
invoice_no = models.IntegerField()
invoice_date = models.DateField(auto_now=True)
due_date = models.DateField(default=datetime.date.today() + datetime.timedelta(days=14))
I guess the quantity should be left out of the Product model, but how can I make a field for it in the Invoice model?