if request.method == 'POST':
try:
form = ExampleForm(request.POST,
instance=Example.objects.get(user=request.user))
except:
form = ExampleForm(request.POST)
if form.is_valid():
m = form.save(commit=False)
is_ok = request.POST.get('is_ok')
m.is_ok = is_ok
m.user = request.user
m.save()
如何添加is_ok
字段instance=Example.objects.get(user=request.user)
注意:我不能将此字段添加到模型表单中。
如果我更改现有数据,我的is_ok
值将更改为默认值
编辑:
<input type="checkbox" disabled="disabled" checked="checked" name="is_ok" id="id_is_ok"/>
如果禁用此输入,则 my is_ok = request.POST.get('is_ok')
= None