Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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'})
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading