-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Closed
Description
Create an object with ImageField within REST API are not automatically populated values into width_field and height_field.
Create the same object from django admin - width and heights are properly passed.
I dig deeper issue and found following things.
Dimensions assigned in ImageFileDescriptor setter.
Setter __set__ from ImageFileDescriptor function executed only once, right after model execute .save() method.
When create object from django admin, this setter executed few times before .save() method.
Currently i solve this issue with hack:
class Photo(models.Model):
photo = models.ImageField(
height_field='photo_height',
width_field='photo_width',
)
class Meta:
ordering = ('-created_at',)
def save(self, *args, **kwargs):
# add additional setter call before save model to re-assign width/height into our fields
self.photo = self.photo
return super(CommentPhotoRel, self).save(*args, **kwargs)But i believe that there are some reasons, setter called only one time after save, rather than admin model creation, where setter called few times before save.
Any thoughts ?
Checklist
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
Metadata
Metadata
Assignees
Labels
No labels