这是通过
clean表单上的方法完成的。但是,您需要设置
foo_dateand
foo_timeto
required=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')


