多個模型我有這三類Django的 - 更新從一個視圖(形式表)
class Product(models.Model):
name = models.CharField(max_length=50)
class Input(models.Model):
idProduct = models.ForeignKey('Product', on_delete=models.CASCADE)
quantity = models.IntegerField()
price = models.DecimalField(max_digits=5, decimal_places=2)
created_at = models.DateTimeField(auto_now=True)
class Output(models.Model):
idProduct = models.ForeignKey('Product', on_delete=models.CASCADE)
quantity = models.IntegerField()
created_at = models.DateTimeField(auto_now=True)
我whant做出視圖/表格這樣
| output-quantity->product | product-name | input-quantity->product |
名單表所有來自DB的產品併爲每個產品添加數量(輸入或輸出)
接下來,我總結輸入和輸出,然後減去它們以獲得每個產品的庫存記錄。
我的問題是我不明白我怎麼可以在視圖中同時使用三種型號/形成
到目前爲止,您嘗試了什麼?請顯示您的查看代碼。 – Soviut
你可以,你可以在這裏分享你的看法 – Cadmus
我不知道該怎麼做。 我沒有在網上哪裏可以使用多種模型在同一視圖 –