假设我有一个包含两个字段的类,并且两个字段都是空白的,但我希望至少填写一个字段。
class MyClass(models.Model):
url1 = models.URLField(blank=True)
url2 = models.URLField(blank=True)
def clean(self):
if not self.url1 and not self.url2:
raise forms.ValidationError('message here')
return self.url1
我想是因为我将这两个字段设置为空白=真。不知道在这里使用 clean() 是否正确以及从中返回什么。
{{form.non_field_errors}} 中没有显示任何内容
谢谢