I have the below model form and want to add custom validation to a field called 'billable_work'.
How do I access a field 'project' which was submitted in the form? I want to check the value of project ('p' in the below example) but can't locate the proper syntax so that I can test the submitted value. Any help would be appreciated.
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']