Skip to content

CloudinaryField add width_field and height_field attributes #62

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

Closed
wants to merge 1 commit into from

Conversation

ilyatikhonov
Copy link
Contributor

@ilyatikhonov ilyatikhonov commented Dec 6, 2015

Django's ImageField has an option to fill special model's fields with width and height of the uploaded image.

For easier migration from ImageField I suggest adding the same options to CloudinaryField.


Add width_field and height_field attributes to behave like original Django's ImageField

ImageField docs: https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ImageField

Width and height fields will be filled by original image size after image upload.

@LorisLunedei
Copy link

Any news for this pull request?

@ilyatikhonov
Copy link
Contributor Author

Hi @tocker, do you have any objections to merging this?

@tocker
Copy link
Contributor

tocker commented Nov 17, 2016

@ilyatikhonov Thanks for the pull request!

The code looks good, but can you please add tests for this feature?
We've added a django_tests module to test Django-specific functionality.

@nadavofi nadavofi self-assigned this Nov 22, 2016
@tocker
Copy link
Contributor

tocker commented Feb 1, 2018

Merged manually.
@ilyatikhonov thanks for the pull request!

@tocker tocker closed this Feb 1, 2018
@toert
Copy link

toert commented Apr 7, 2018

The only question is "How to use it?"

to_python() returns CloudinaryResource which doesn't have these fields. How can I get CloudinaryField object?

@idobarnoam
Copy link
Contributor

Hi @toert

It's possible to use it in the following way:

Define 2 new fields in the model:
image_width, image_height (you can give them any name)

and then Set them in initialisation of the CloudinaryField
width_field='image_width', height_field='image_height'

For example:

class MyModel(models.Model):
image_width = models.PositiveIntegerField(null=True)
image_height = models.PositiveIntegerField(null=True)
image = CloudinaryField('image', null=True, width_field='image_width', height_field='image_height')

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

Successfully merging this pull request may close these issues.

6 participants