[英]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
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)
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)
I want model_B to have value_4 as separate column in database table(model_B)我希望 model_B 将 value_4 作为数据库表中的单独列(model_B)
For this purpose, you can use computedfield:为此,您可以使用计算域:
https://pypi.org/project/django-computedfields/ https://pypi.org/project/django-computedfields/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.