[Answer]-How to call method save() in a Django model class using attr string name?

1👍

why not to use getattr/hasattr calls? You can write something like this:

full_attr_name = 'image_' + attr_name
if hasattr(self, full_attr_name):
    getattr(self, full_attr_name).save(filename, suf, save=False)

Hope, you have caught the idea.

👤Dmitry

0👍

If your having images of different sizes then I think using sorl-thumbnail would have been a better approach. Link attached.

http://sorl-thumbnail.readthedocs.org/en/latest/examples.html#model-examples

👤Anup

Leave a comment