django-imagekit icon indicating copy to clipboard operation
django-imagekit copied to clipboard

Generate images in postsave

Open stiefenswiegel opened this issue 3 years ago • 1 comments

Hi,

i would like to generate all temp image sin a postsave command. How can i generate the images for a specific instance?

stiefenswiegel avatar Jan 20 '22 10:01 stiefenswiegel

In case you are using ImageSpecField in your model, this could be a workaround:

from imagekit.cachefiles import ImageCacheFile

def generate_temp_images(obj):
  for attr in dir(obj):
    try:
        val = getattr(obj, attr)
        if isinstance(val, ImageCacheFile):
            val.generate(force=True)
    except:
        pass

As a note, the value of fields with ImageSpecField type are determined by ImageSpecFileDescriptor descriptor returning ImageCacheFile objects. So, we can use the value of these fields to generate our temp files.

armanexplorer avatar Apr 25 '22 15:04 armanexplorer