问题描述
如何在表单中创建外键字段,但是一旦提交表单,仍然允许此字段被认定为有效?根据W3C,一旦表单被提交,残疾人专栏就被遗漏了....使用下面的代码,我可以将该字段设置为禁用,因此只读,但是我的表单不会通过
How do I make a foreign key field in a form read only but still allow this field to be recognized as valid once the form is submitted? According to W3C, disabled fields are left out once the form is submitted....using the code below, I can set the field as disabled, thus readonly, but my form doesn't go through
def __init__(self, *args, **kwargs):
super(IssuesForm, self).__init__(*args, **kwargs)
self.fields['vehicle'].widget.attrs['readonly'] = True
想法....?
推荐答案
我不知道Django或Python语法,但是,类型的输入字段=隐藏可能是您正在寻找的。如果您想使用禁用字段仍然显示该值,那么您也可以这样做,并依赖于隐藏字段的实际值。
I don't know the Django or Python syntax, however, an input field of type="hidden" might be what you're looking for. If you wanted to still display the value using a disabled field, you could do that too, and rely on the hidden field for the actual value.
这篇关于以django形式将外键字段设置为只读,并仍然允许提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!