[英]Change values of bound form
我有一个绑定的django表单,但我最终要更改一个整数字段。 绑定后但渲染之前,如何访问和更改表单中字段的值。 我试过了:
class TestForm(forms.Form):
depth = forms.IntegerField(initial=0)
def incDepth(self):
self.fields['depth']=self.fields['depth']+1
f=TestForm()
f.incDepth()
print f.as_table()
但是我不明白如何正确访问IntegerField值。...有什么建议吗?
您可以在表单的init()方法中执行此操作:
def __init__(self,*args, **kwargs):
super(Model, self).__init__(*args, **kwargs)
self.fields['depth'] = self.depth['fields'] + 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.