簡體   English   中英

制作一個 Django model class 其字段值之一由其他模型的字段值計算,並且它必須存在於我的實際數據庫表中

[英]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

模型.py

from django.db import models

class model_A(models.Model):
  value_1 = models.IntegerField()
  value_2 = models.FloatField()

class model_B(modles.Model):
  value_3 = models.FloatField()
  value_4 = (model_A.value_1 - model_B.value_2)

管理員.py

from django.contrib import admin

# Register your models here.
from .models import model_A, model_B

model_lst = [model_A, model_B]

for i in model_lst:
    admin.site.register(i)

我希望 model_B 將 value_4 作為數據庫表中的單獨列(model_B)

為此,您可以使用計算域:

https://pypi.org/project/django-computedfields/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM