pycloudinary icon indicating copy to clipboard operation
pycloudinary copied to clipboard

CloudinaryFileField doesn't show checkbox for clear the field

Open andres8511 opened this issue 3 years ago • 2 comments

Hello, I'm ussing the CloudinaryField in model to upload the image in my project but today I need add more options like "quality" so I implemented CloudinaryFileField in forms, it's works perfect. The issue that I have is the checkbox to clear (or delete) the file is dissapeared. So, is there a way to add the checkbox? logo = CloudinaryFileField( options={ 'folder': "logos/", #'eager': [{'crop': 'fill', 'width': 150, 'height': 100}] 'overwrite': True, 'quality': 20, }) This is before with the checkbox image

And when I use CloudinaryFileField image

Regards

andres8511 avatar Oct 07 '20 14:10 andres8511

Thanks @andres8511, we're on it.

YomesInc avatar Oct 18 '20 23:10 YomesInc

Please try adding required=False to CloudinaryFileField parameters, e.g.

logo = CloudinaryFileField(
		    options={'quality': 5 },
		    required=False
	    )

Since, CloudinaryFileField is a child class of forms.FileField, checkbox input to clear the field’s value is shown if the field is not required and has initial data.

A more complete example of how to use together models.py, admin.py, and forms.py is below:

# models.py

class Photo(models.Model):
	image = CloudinaryField('image',  null=True, blank=True)

# forms.py

class PhotoForm(ModelForm):
    class Meta:
        model = Photo
        fields = ['image']

    image = CloudinaryFileField(
		    options={'quality': 5 },
		    required=False
	    )

# admin.py

@admin.register(Photo)
class PhotoAdmin(admin.ModelAdmin):
    form = PhotoForm

YomesInc avatar Feb 26 '21 14:02 YomesInc