购买者每次都从供应商那里购买一种产品类型(包括服务器产品)。我不知道如何在django admin中添加采购记录,其中包括购买日期,供应商名称,产品类型,产品名称及其数量。
class ProductSupplier(models.Model):
product_supplier = models.CharField(max_length=50,unique=True,verbose_name="product supplier")
class ProductType(models.Model):
product_type = models.CharField(max_length=50,verbose_name="product type")
product_suppliers = models.ManyToManyField(ProductSupplier,through='BuyProducts')
class Product(models.Model):
product_name = models.CharField(max_length=50,verbose_name="product name")
product_type = models.ForeignKey(ProductType,on_delete=models.CASCADE,verbose_name="product type")
class BuyProducts(models.Model):
product_type = models.ForeignKey(ProductType,on_delete=models.CASCADE)
product_supplier = models.ForeignKey(ProductSupplier,on_delete=models.CASCADE)
date_bought = models.DateField()
def __str__(self):
return "bought %s from %s on %s" % (self.product_type,self.product_supplier,self.date_bought)
我可以在django admin中添加或编辑采购记录,其中包括购买日期,供应商名称和产品类型。但是,我无法添加或编辑产品名称及其数量。任何建议都非常欢迎。
像这样的sql表:
BuyProductType: buy_product_type_id,product_type_id,供应商ID,购买日期
BuyProductQuantity: buy_product_quantity_id,buy_product_type_id,product_id,数量