3

我刚刚在 Django 1.4 下将一个站点从 Django-CMS 2.3.5 移动到 2.4.1(在 Stackoverflow的帮助下)。

我现在正在升级到 Django 1.5,这很困难,因为我需要将旧的单独用户配置文件更新为新的自定义用户模型。我遵循了这里的优秀说明,并将所有引用替换Usersettings.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 使用新的用户模型?

谢谢!

4

2 回答 2

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
于 2013-07-02T17:31:41.933 回答
0

对于有这个问题的其他人,这是我从https://github.com/divio/django-cms/issues/1798学到的内容的总结。

有四种可能的选择:

  1. 如果您需要自定义用户模型的名称不是 User,则需要等待。
  2. 您可以调用自定义用户模型 User - 虽然当我尝试此操作时,我收到有关与相关 m2m 字段冲突的错误。上述链接中有一些进一步的细节可能有助于解决这个问题。
  3. Django 1.5 仍然允许您使用用户配置文件。因此,如果您可以使用已弃用的功能,您仍然可以将 Django-CMS 2.4 和 Django 1.5 与用户配置文件一起使用,而不是自定义用户模型。(我在这里误读了 Django 文档,并认为 Django 1.5 不支持用户配置文件。)
  4. 您通常可以在没有用户配置文件或自定义用户模型的情况下逃脱 - 它们最适合用于添加专门用于用户身份验证的数据。相反,您可以使用与 User 具有一对一关系的另一个模型,并使用反向关系来访问它。

就我而言,我将在短期内选择#3,在长期内选择#4。

于 2013-05-23T22:57:11.943 回答