相关疑难解决方法(0)

Django - 无法使用动态upload_to值为ImageField创建迁移

我刚刚将我的应用程序升级到1.7(实际上还在尝试).

这就是我在models.py中所拥有的:

def path_and_rename(path):
    def wrapper(instance, filename):
        ext = filename.split('.')[-1]
        # set filename as random string
        filename = '{}.{}'.format(uuid4().hex, ext)
        # return the whole path to the file
        return os.path.join(path, filename)
    return wrapper

class UserProfile(AbstractUser):
    #...
    avatar = models.ImageField(upload_to=path_and_rename("avatars/"),
                               null=True, blank=True,
                               default="avatars/none/default.png",
                               height_field="image_height",
                               width_field="image_width")
Run Code Online (Sandbox Code Playgroud)

当我尝试时makemigrations,它抛出:

ValueError: Could not find function wrapper in webapp.models.
Please note that due to Python 2 limitations, you cannot serialize unbound method functions (e.g. a method declared
and used in the same class body). …
Run Code Online (Sandbox Code Playgroud)

python django django-migrations

27
推荐指数
1
解决办法
6050
查看次数

标签 统计

django ×1

django-migrations ×1

python ×1