sverrejoh
sverrejoh

Reputation: 16860

Require one of a set of fields in a form to be valid

How do I make a Django form where the user can choose between several ways of providing the data, and I need one of them to be valid.

Say that I have a user profile where the user can choose between profile picture as URL or a imagefile:

class UserProfile(forms.Form):
    picture_url = forms.URLField()
    picture_file = forms.ImageField()
    ...

Is there any obvious way of doing this, without writing my own clean() method?

Upvotes: 0

Views: 77

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600041

Writing your own clean() method is the way to do it.

Upvotes: 2

Related Questions