Last active
December 12, 2015 07:49
-
-
Save matthewwithanm/4739926 to your computer and use it in GitHub Desktop.
ImageSpec with Suffixed Filenames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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