【发布时间】:2014-10-12 22:17:25
【问题描述】:
假设我们得到了以下 Model 和 ModelForm:
from django.db import models
from django import forms
class A(models.Model):
a = models.IntegerField()
b = models.IntegerField()
c = models.IntegerField() # either c = a * b or c = 2 * a * b
class AForm(forms.ModelForm)
class Meta:
model = A
fields = ('a', 'b')
double = forms.BooleanField(required=False)
现在我希望如果用户检查double 然后 cgets 更新到 2 * a * b 和 a * b 否则。
编辑:我想使用 AForm 作为 API,这样我的所有其他代码都可以通过表单与 A 实例一起使用。所以我想把所有的逻辑都封装在ModelForm里面。
请帮助我提出您的想法。
【问题讨论】:
标签: django django-forms