how to remove upload image validation in Django?



How can I remove this validation in django? enter image description here

code in Django is like this:

image = models.ImageField(upload_to="data", null=True, blank=True)


If you set the field in a ModelForm, it will no longer be constructed by the corresponding model field, hence it will not take blank=True into account.

What you can do is only override the widget, so work with:

class SomeModelForm(forms.ModelForm):
    # no image = …

    class Meta:
        model = SomeModel
        fields = ['image', 'and', 'other', 'fields']
        widgets = {
            'image': forms.FileInput(attrs={'class': 'file-upload-input', 'id': 'file-selector'})

Answered By – Willem Van Onsem

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More