M
M
Mikkkch2020-12-06 13:01:52
Django
Mikkkch, 2020-12-06 13:01:52

Is there any advantage to using a decorator on models containing an ImageField?

Hello, I often see something like this in some code:

def contain_photos(model):
    upload_path = model.__name__.lower() + 's'
    image_field = models.ImageField(upload_to=upload_path)
    setattr(model, 'photo', image_field)


@contain_photos
class Animal(models.Model):
    pass

Does it make sense to do something like this? Or is it just simple to add an ImageField field to each model and set the appropriate path for loading images?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question