Home > Enterprise >  how to remove upload image validation in Django?
how to remove upload image validation in Django?

Time:12-01

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)

CodePudding user response:

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'})
        }
  • Related