我有以下模型表单,并希望将自定义验证添加到名为“billable_work”的字段中。
如何访问表单中提交的字段“项目”?我想检查项目的值(以下示例中的'p'),但无法找到正确的语法,以便我可以测试提交的值。任何帮助将不胜感激。
class EntryForm(forms.ModelForm):
class Meta:
model = Entries
exclude = ('billable_work','notes')
billable_work = forms.BooleanField()
notes = forms.CharField(widget=forms.Textarea,required=False)
def clean_billable_work(self):
b = self.cleaned_data['billable_work']
p = form.fields['project']
if b == True and p == 523:
raise forms.ValidationError(_("Entries cannot be both billable and NONE: Indirect."))
return self.cleaned_data['billable_work']