views:

29

answers:

1

Given the following model, how do I require that atleast one of the two fields has been given a value?

class ZipUpload(models.Model):
    zip_file = models.FileField(upload_to="/tmp", blank=True,
                                help_text='Select a file to upload.')
    zip_file_path = models.FilePathField(path="/tmp", blank=True,
                                help_text="A path to a file on the server)

I'm working on a small site with a small set of users, so I was hoping to make this work with just using the standard admin-site. I have considered overriding Model.save(), and adding a check there, but then I don't know how to alert the user of the error in a good way.

+3  A: 

This kind of validation is what a customized Form is for. Define a Form, write validation methods in the Form. Bind the Form to the Model to create the Admin interface.

S.Lott
Thanks, I had a feeling I was looking in the wrong direction. :)
Epcylon