Skip to content

Instantly share code, notes, and snippets.

@eculver
Last active December 29, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eculver/7635945 to your computer and use it in GitHub Desktop.
Save eculver/7635945 to your computer and use it in GitHub Desktop.
Example of deleting a cached KVStore instance that sorl.thumbnail thumbnail templatetag creates. Pretty edge, but handy when thumbnails aren't being generated for whatever reason.
from sorl.thumbnail import default
from myapp.models import MyModel
# Get an model instance that has a File/ImageField associated with it. In this
# case the `thumb` attribute is an ImageField that we'd like to generate thumbnails for.
m = MyModel.objects.get(pk=10)
# Note the options passed to this method -- they are applied to the cache key so
# the ImageFile instance that is returned will be different for a different set
# of options kwargs provided here. In this case, the only option is `upscale=False`.
thumb = default.backend.get_thumbnail(m.thumb, "300", upscale=False)
# By default, thumbnails will be deleted along with the KVStore record.
default.kvstore.delete(thumb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment