问题描述
当两个字段为空白时,我想显示一个错误,我想成为其中一个空白而另一个不为空白。所以我提出了一个验证错误,但它看起来像这样: This is the Validation error now
而且我想像regexp类型的弹出窗口一样,我尝试了不同类型的验证,但是我不知道如何弹出这样的错误。 This is pop up validation error 我已经研究了一段时间,但没有发现任何有用的东西,我是Django开发的初学者,我认为这是JavaScript问题或CSS,但我不知道该怎么做。你们可以帮我吗? 在此先感谢您,如果不是一个好问题或降级程度很低,对不起。 我还将发布来自ModelForm的代码,让您看看自己做了什么。
class Upload_Document(forms.ModelForm):
def clean(self):
cleaned_data=super().clean()
url=cleaned_data.get('site')
file_upload=cleaned_data.get('file_upload')
msg='This field or File field is required'
if bool(file_upload) ==False and bool(url)==False:
self.add_error('site',msg)
class Meta:
model= Form_Data
fields =['title','author','email','document_type','keywords','abstract','authentication','site','comments','file_upload']
我也会放置模型:
class Form_Data(models.Model):
title=models.CharField(unique=True,max_length=100,blank=False)
author=models.CharField(max_length=100)
email=models.EmailField(max_length=250,blank=False,null=True)
document_type=models.CharField(choices=DOCUMENT_TYPES,max_length=255,default=None)
keywords=models.CharField(max_length=500)
abstract=models.TextField(null=True,blank=True)
authentication=models.CharField(choices=DOCUMENT_AUTHENTICATION_LEVEL,default=None,max_length=500)
site=models.URLField(blank=True,null=True)
comments=models.TextField(null=True,blank=True)
file_upload=models.FileField(upload_to='forms/',blank=True,null=True)
def __str__(self):
return self.title
我想在某人填写表格时被要求是文件字段或网址字段之一
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)