![](/img/trans.png)
[英]Make a Django model class whose one of the field value is calculated by other model's fields values and it must be present in my actual Database table
[英]Creating a model in Django whose field has multiple other fields inside it
我對 Django 很陌生,想澄清一個菜鳥疑問。 假設我對 django 中的 model Scans
有一個發布請求。
同樣的 json 數據看起來像
[{“id”:1,“結果”:{“低”:3,“中”:6,“高”:7},“機器”:“Windows”,“報告”:“是”]
model 應該是什么樣子? 我不知道應該給results
什么字段類型。
您還可以創建兩個模型Scans
和Results
並在它們之間創建如下關系
class Scans(models.Model):
machine = models.CharField(max_length = 100)
# assuming that report is by default false
report = models.BooleanField(default = False)
results = models.ForeignKey(Results, on_delete = models.CASCADE)
class Results(models.Model):
low = models.IntegerField()
medium = models.IntegerField()
high = models.IntegerField()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.