我刚刚在Django 1.4下将一个站点从Django-CMS 2.3.5移动到2.4.1(来自Stackoverflow的help)。
我现在正在升级到Django 1.5,这很难,因为我需要将旧的单独用户配置文件更新为新的自定义用户模型。我遵循了优秀的说明here,并将所有对User
的引用替换为settings.AUTH_USER_MODEL
。
不幸的是,Django-CMS的模型显然仍然引用User
:当我输入manage.py runserver
时,我收到此错误:
CommandError: One or more models did not validate:
cms.pagemoderatorstate: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.globalpagepermission: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pagepermission: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageuser: 'user_ptr' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageuser: 'created_by' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageusergroup: 'created_by' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
如何让Django-CMS使用新的用户模型?
谢谢!
答案 0 :(得分:1)
有一个非常简单的解决方案。只需在导入CMSPlugin之前注册您的自定义用户。示例:
from django.db import models from django.contrib.auth import models as auth_models from django.contrib.auth.models import AbstractUser class User(AbstractUser): telephone = models.CharField(max_length=100) email = models.CharField(max_length=100) auth_models.User = User from cms.models import CMSPlugin
答案 1 :(得分:0)
对于有此问题的其他人,以下是我从https://github.com/divio/django-cms/issues/1798学到的内容摘要。
有四种可能的选择:
在我的情况下,我将在短期内使用#3,在长期使用#4。