def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
formset = context['formset']
if self.object.bool_field:
for frm in formset:
frm.fields['another_field'].initial = frm.instance.value
context['formset'] = formset
return context
条件很好,我记录了一些信息并且工作正常。但是,在呈现表单时,another_field字段的值不正确。我猜测formset不可变(没有给出错误),我在这里遗漏了什么?
提前致谢