If you attempt to add custom validation to a newforms-admin model adding/editing page that runs against more than one field (and hence should be in the form's "clean" method, rather than a clean method associated with a particular field) you run in to problems. Here's the example code:
def custom_clean(self):
image_url = self.cleaned_data.get('image_url', None)
image = self.cleaned_data.get('image', None)
if not image and not image_url:
raise forms.ValidationError("You must upload OR enter an image")
return self.cleaned_data
class EntryOptions(admin.ModelAdmin):
def get_form(self, request, obj=None):
form = super(EntryOptions, self).get_form(request, obj)
form.clean = custom_clean
return form
This works in as much as you get a message about there being errors on the page, but the actual errors are not displayed anywhere. They should be displayed in a list at the top of the page.
Forms have a non_field_errors() method that can be used for this purpose.