from django.utils.deconstruct import deconstructible


@deconstructible
class PathAndRename(object):

    def __init__(self, sub_path):
        self.path = sub_path

def __call__(self, instance, filename):
    ext = filename.split('.')[-1]
filename = '{}.{}'.format(uuid4().hex, ext)
return os.path.join(self.path, filename)
path_and_rename = PathAndRename('/avatars')
Django – невозможно создать миграции для ImageField с динамическим значением upload_to