Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make FileField in django optional?

If you're using a forms.FileField() in a forms.Form derived class, you can set:

class form(forms.Form):
    file = forms.FileField(required=False)

If you're using a models.FileField() and have a forms.ModelForm assigned to that model, you can use

class amodel(models.Model):
    file = models.FileField(blank=True, null=True)

Which you use depends on how you are deriving the form and if you are using the underlying ORM (i.e. a model).