pycloudinary
pycloudinary copied to clipboard
CloudinaryFileField doesn't show checkbox for clear the field
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
And when I use CloudinaryFileField
Regards
Thanks @andres8511, we're on it.
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