Skip to content

Instantly share code, notes, and snippets.

@matthewwithanm
Last active December 12, 2015 07:49
Show Gist options
  • Save matthewwithanm/4739926 to your computer and use it in GitHub Desktop.
Save matthewwithanm/4739926 to your computer and use it in GitHub Desktop.
ImageSpec with Suffixed Filenames
from django.db import models
from imagekit import ImageSpec
from imagekit.models import ImageSpecField
from imagekit.utils import get_field_info
from imagekit import register
import os
class TvSpec(ImageSpec):
suffix = '-tv'
@property
def cachefile_name(self):
instance, attname = get_field_info(self.source)
name = source_name_as_path(self)
ext = os.path.splitext(name)[1]
return u'%s%s%s' % (os.path.dirname(name), self.suffix, ext)
register.generator('myapp:tv', TvSpec)
class MyModel(models.Model):
thumbnail = ImageSpecField(id='myapp:tv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment