Worked this one out.
For anyone interested ...

def save(self):
        super(Book, self).save()

        file_ext = os.path.splitext(str(self.cover.name))[1]
        new_filename = '%s%s' % (self.slug, file_ext)
        new_filepath = os.path.join(settings.MEDIA_ROOT, new_filename)
        old_filepath = os.path.join(settings.MEDIA_ROOT, self.cover.name)
        shutil.move(old_filepath, new_filepath)
        self.cover.name = os.path.join('p/', new_filename)

        super(Book, self).save()




On Aug 24, 10:36 am, The Danny Bos <danny...@gmail.com> wrote:
> Hey there, I've got the below code.
> Can someone help me fill in the gaps to rename the image to the
> 'SLUG'?
>
> In the end I'm hoping for images like so:
>
>  ...com/books/book-title.jpg
>  ...com/books/thumbs/book-title.jpg
>
> Here's my save() definition from models.py:
>
> def save(self):
>         super(Book, self).save()
>
>         image_path = '%s%s' % (settings.MEDIA_ROOT, str(self.cover))
>         path, filename = os.path.split(image_path)
>
>         thumb_name = '%s/thumbs/%s' % (path, filename)
>
>         gen_thumb(image_path, thumb_name, size=160)
>         self.thumb = '%s' % filename
>
>         super(Book, self).save()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to