如何使表单中的外键字段只读但仍允许在提交表单后将该字段识别为有效?根据 W3C,一旦提交表单,禁用字段就会被忽略......使用下面的代码,我可以将字段设置为禁用,因此只读,但我的表单不会通过
def __init__(self, *args, **kwargs):
super(IssuesForm, self).__init__(*args, **kwargs)
self.fields['vehicle'].widget.attrs['readonly'] = True
Run Code Online (Sandbox Code Playgroud)
想法……?