ImageField always calling update_dimensions_fields

106 views
Skip to first unread message

ggi...@gmail.com

unread,
Dec 3, 2016, 7:47:06 PM12/3/16
to Django users

I needed to get to the width and height of an image. After discovering that doing so on an ImageField loads the file, I added width_field and height_field to my model.

I did a migration and starting using the new model.

However, it *always* seems to call update_dimension_fields every time the model is loaded.

I'm on 1.9.9 if that makes a difference.

I see there was an old bug where this was addressed https://code.djangoproject.com/ticket/11084

It seems to be broken for me. Any ideas what is going on?

Thanks,

      Greg

Daniel Roseman

unread,
Dec 4, 2016, 7:31:48 AM12/4/16
to Django users
You need to show your model code.
--
DR. 

ggi...@gmail.com

unread,
Dec 4, 2016, 2:00:39 PM12/4/16
to Django users
What I see is that when I load my page, it calls update_dimension_fields for every image. The model is simple.


class Photo(models.Model):
width = models.PositiveIntegerField(blank=True, null=True, editable=False, default="0")
height = models.PositiveIntegerField(blank=True, null=True, editable=False, default="0")
image = ImageField(upload_to=upload_to, width_field='width', height_field='height')
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="uploaded_photos")
title = models.CharField(max_length=255)
slug = extension_fields.AutoSlugField(populate_from='title', blank=True)
caption = models.CharField(max_length=255, blank=True)
date_added = models.DateTimeField(default=timezone.now)

class PhotoCollection(models.Model):
name = models.CharField('name', max_length=250)
slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
description = models.TextField(blank=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="uploaded_collections")
date_added = models.DateTimeField(default=timezone.now)
photos = models.ManyToManyField('photos.Photo', related_name='collections', blank=True)

Reply all
Reply to author
Forward
0 new messages