如何在Django中以一种形式组合几种模型?

时间:2019-02-10 18:16:23

标签: django python-3.x

我在Django中有4个模型:产品,订单,lines_Orders和发票。基于这些模型,我想创建一个表格,该表格将在给定订单编号的情况下生成发票。但是我不知道这些视图如何以及如何将这些模型组合成一种形式。

class Product(models.Model):
    # productId=models.IntegerField(auto_created=True)
    customerId=models.ForeignKey(Customers, on_delete=models.CASCADE)
    productNumber=models.CharField(max_length=15, unique=True)
    productDescription=models.CharField(max_length=25)
    unitPrice = models.FloatField()
    storageQuantity=models.FloatField()

class Orders(models.Model):
    orderID=models.AutoField(primary_key=True)
    customerID = models.ForeignKey(Customers, on_delete=models.CASCADE)
    oderDate = models.DateTimeField()

class Order_lines(models.Model):
    oderID = models.ForeignKey(Orders, on_delete=models.CASCADE)
    productNumber=models.ForeignKey(Product, on_delete=models.CASCADE)
    quantity = models.FloatField(default=0.00)

class Invoice(models.Model):
    dateInvoice=models.DateField()
    receiveDate=models.DateField()
    OrderNumber=models.ForeignKey(Orders, on_delete=models.CASCADE)

请协助

1 个答案:

答案 0 :(得分:0)