2👍
✅
You need to overwrite the form’s clean
method and assign an error message to a field. Here’s an example where all three fields get an error message if they are all blank, adapted from the Django docs:
from django import forms
class ArtworkForm(forms.Form):
def clean(self):
cleaned_data = super(ArtWorkForm, self).clean()
image_file = cleaned_data.get("image_file")
video_file = cleaned_data.get("video_file")
video_url = cleaned_data.get("video_url")
if not (image_file or video_file or video_url):
msg = "your error message."
self.add_error('image_file', msg)
self.add_error('video_file', msg)
self.add_error('video_url', msg)
Source:stackexchange.com