[Answered ]-Using a dictionary (or other structure) key in a variable name

2👍

You want to use setattr(). setattr(x, 'y', z) is equivalent to x.y = z (note that the second argument is a string – in your case, it will be the key string). So in your case, you could do:

setattr(self.instance, key, self.saving_path + self.slug + '_' + key + '.' + self.image_format)

Leave a comment