views:

404

answers:

1

I have a model that looks like this:

class ProjectImage(models.Model):
    big_thumb = ThumbnailField(upload_to='profiles', size=(500, 500))
    med_thumb = ThumbnailField(upload_to='profiles', size=(300, 300))
    small_thumb = ThumbnailField(upload_to='profiles', size=(100, 100))

I associate ProjectImage with a Project as a TabularInline. In the admin, I'd like to be able to say if the medium and/or small thumbnails were not provided, use the same image as the big thumbnail. However, I'm having a hard time figuring out how to specify this behavior.

A: 

You have two options in this case, you can either over-ride ProjectImage's save defintion and have it copy big_thumb to med_thumb and small_thumb if they are None, or just create a simple model definition to display each field.

def get_med_thumb_url(self):
    if self.med_thumb is None:
         return self.big_thumb.url

    return self.med_thumb.url

And do the same for small_thumb That keeps you from fidgeting with the save method and having to copy things over and waste space.

I can't remember if ImageField has a get_FOO_url type definition but if it does you could always over-ride that.

Bartek
Can I still override ProjectImage's save method even though it's an Inline form?
btoconnor
I don't see why not. It still has to be saved. :)
Bartek