Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudinaryFileField doesn't show checkbox for clear the field #258

Open
andres8511 opened this issue Oct 7, 2020 · 2 comments
Open

CloudinaryFileField doesn't show checkbox for clear the field #258

andres8511 opened this issue Oct 7, 2020 · 2 comments
Assignees

Comments

@andres8511
Copy link

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

@YomesInc
Copy link
Contributor

Thanks @andres8511, we're on it.

@YomesInc
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants