On Mar 5, 1:17 am, liangent <[email protected]> wrote:
> I created a ImageField img_field with height_field parameter in a
> model,
> added an image, then get it from database.
>
> If I try to access obj.img_field.height and obj.img_field.width,
> where do django get this data from?
>
> Cached data when SELECTed from db?
> Or get size with PIL then cache it?

The latter. When you access (i.e. read) obj.img_field.width, Django
will use PIL to fetch that image's dimensions, cache those dimensions
in a special attribute of that image instance, and then return the
width to you. It will not return the value from your img_field
parameter on the model.

There's a discussion of this here: http://code.djangoproject.com/ticket/8307

So if you want to always receive the DB stored values for an image's
width and height, use obj.width_field and obj.height_field directly
and not obj.image_field.width. The obj.width_field and
obj.height_field values are populated by Django whenever you save an
image field in your model.

The above mentioned ticket discusses why the DB cached values are not
returned when you access obj.img_field.width, height.

-Rajesh D

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to