Last active
December 29, 2015 07:29
-
-
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.
This file contains 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 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