我有表格:
class AdClientForm(forms.Form):
text = forms.CharField(label=u'text', required=True, widget=forms.Textarea)
image = forms.ImageField(widget=AdmImageWidget(), label=u'Image', required=False)
def clean(self):
???
如何检查是否使用了场图?这意味着用户已选择要上传的文件。
答案 0 :(得分:0)
你试过了吗?
def clean(self):
cleaned_data = super(AdClientForm, self).clean()
if not cleaned_data['image']:
raise forms.ValidationError("No image")
return cleaned_data