Auto-filling others ImageFields based on the original one

9 views
Skip to first unread message

Sasa Trifunovic

unread,
Oct 31, 2014, 11:35:00 AM10/31/14
to django...@googlegroups.com
Hi,

I have to save 3 versions of uploaded photo (and i dont want to use solr) , original one and two which are resized versions of the original one.
I need  those two additional photos as ImageFields in my model , due to the fact that i want to use django ORM.

   
Class Post(model.Models):
    
    #...
    photo = models.ImageField(upload_to="photo_album")
    original_photo = models.ImageField(upload_to="photo_album/originals", null=True)
    thumbnail = models.ImageField(upload_to="photo_album/thumbnails", null=True)



I have tried overriding the save method 

 
    def save(self):
            
self.thumbnail.file = self.photo.file
            
self.original_photo.file = self.photo.file
            
super(Post, self).save()


But that is not working (why?).

Any advice on how to solve this is much appreciated. Thanks!

Mike Dewhirst

unread,
Oct 31, 2014, 9:42:48 PM10/31/14
to django...@googlegroups.com
Try ...

def save(self, *args, **kwargs):
self.thumbnail.file = self.photo.file
self.original_photo.file = self.photo.file
super(Post,self).save(*args, **kwargs)

The args and kwargs are ORM params used to control saving. You need to
pass them back to the built-in save() method.

Good luck

>
> Any advice on how to solve this is much appreciated. Thanks!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3907a3ed-3d39-4a07-8ab9-e80a9fe6b32e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3907a3ed-3d39-4a07-8ab9-e80a9fe6b32e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages