I want to set a default value in a form and it will be reset as approval = False
in every update. I tried something but it did not work it doesn't change. How can I fixed it?
forms.py
class UpdateDoaTableForm(forms.ModelForm):
approval = forms.BooleanField(required=False,
initial=False,
label='Approved',
widget=forms.HiddenInput()
)
class Meta:
model = DoaTable
fields = ('limit', 'approval')
views.py
def update_limit(request, id):
limiting = get_object_or_404(DoaTable, id=id)
form = UpdateDoaTableForm(request.POST or None, request.FILES or None, instance=limiting)
limiting_item = DoaTable.objects.filter(id=id)
if form.is_valid():
form.save()
return redirect('approvals:update_limit_list')
context = {
'form': form,
'limiting_item': limiting_item,
}
return render(request, 'limitUpdate.html', context)
models.py
class DoaTable(models.Model):
...
approval = models.BooleanField(default=False)
question from:
https://stackoverflow.com/questions/66060766/how-to-set-a-default-value-for-a-form-in-every-update 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…