我有以下型号:
ynChoice = ((None, 'Acknowledgement not required'),
(True, 'Acknowledgement and consent required'),
(False, 'Acknowledgement required but consent not required'))
class AbstractForm(models.Model):
"""base class for the below 2 classes"""
#require users to say yes and no other than acknowledging #null = not required
yes_no_required = models.NullBooleanField(choices=ynChoice, blank=False)
我把它映射到我的模型上:
class LiveConsentForm(forms.ModelForm):
ynChoice = (
('', '---------------'),
(None, 'Acknowledgement not required'),
(True, 'Acknowledgement and consent required'),
(False, 'Acknowledgement required but consent not required'),
)
yes_no_required = forms.TypedChoiceField(choices=ynChoice,empty_value='')
class Meta:
model = ConsentFormTemplate
这里,ConsentFormTemplate
是AbstractForm
的一个子类。我在表单中编写了yes_no_required
,因为nullbooleanfield的formfield的空值将返回一个None
,这是我不想要的。你知道吗
现在,当我想实例化我的表单来显示一个已有的记录LiveConsentForm(instance=templateInstance)
时,我遇到了一个问题。你知道吗
MytemplateInstance.yes_no_required
的值是None,但是当呈现html时,------
被选中。(当yes_no_required
是True
或False
时,我没有这样的麻烦)
这里需要帮助。你知道吗
好的,我已经看过了窗体.字段以及
结果是,在呈现为html时,结果是“无”仅被视为“”,此处不考虑空的\u值。我不知道为什么@Ignacio Vazquez Abrams dude拿走了他的答案,所以如果你能再把它放回去,我会接受的。你知道吗
相关问题 更多 >
编程相关推荐