这是通过clean
表单上的方法完成的。但是,您需要设置foo_date
and foo_time
torequired=False
,因为clean
仅在验证每个字段之后才调用它(另请参见文档)。
class FooForm(forms.Form)
# your field deFinitions
def clean(self):
data = self.cleaned_data
if data.get('foo_timestamp', None) or (data.get('foo_date', None) and data.get('foo_time', None)):
return data
else:
raise forms.ValidationError('Provide either a date and time or a timestamp')