在完成 Django 教程之后,我现在正在尝试构建一个非常简单的发票应用程序。
我想在发票中添加几个产品,并在 Django 管理员的发票表单中指定每个产品的数量。现在,如果我有相同产品的不同数量,我必须创建一个新的产品对象。
现在我的模型看起来像这样(公司和客户模型被忽略了):
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))
我想数量应该被排除在产品模型之外,但是如何在发票模型中为它创建一个字段?