usage :- put it in python path and refer to it from settings.py
THUMBNAIL_BACKEND = 'full.import.path.to.SEOThumbnailBackend'
Took me a bit to figure it out since i couldn't find an existing example code for it.
1 2 3 4 5 6 7 8 9 10 | from sorl.thumbnail.base import ThumbnailBackend
from os.path import basename
from django.conf import settings
from sorl.thumbnail.helpers import tokey, serialize
class SEOThumbnailBackend(ThumbnailBackend):
def _get_thumbnail_filename(self, source, geometry_string, options):
key = tokey(source.key, geometry_string, serialize(options))
path = '%s/%s/%s' % (key[:2], key[2:4], key)
return '%s%s/%s' % (settings.THUMBNAIL_PREFIX, path, basename(source.name))
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.