Validate that atleast one modelfield has value in Django admin
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开发者_Go百科 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.
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.
精彩评论