gpt4 book ai didi

django 1.5 扩展默认用户模型或替换它

转载 作者:行者123 更新时间:2023-12-01 10:53:46 25 4
gpt4 key购买 nike

环境:Django 1.5.1 + Django CMS 2.4.1 + Zinnia latest + 我的自定义应用程序 + 自定义 Django CMS 插件

基本上我可以扩展默认的 Django (1.5.X) 用户模型喜欢Django Ribbit Tutorial on NetTuts+

替换为完全定制的模型,如 Django Dev doc或段落中的 Django2Scoops 示例:“处理用户模型”

为了测试我决定使用 Subclass AbstractUser来自 Django2Scoops 书:“如果您喜欢 Django 的用户模型字段,但需要额外的 ..fields,请选择此选项。”

但是我有以下错误:

notification.noticesetting: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL. cmsplugin_zinnia.latestentriesplugin: 'authors' 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.

经过几个小时的阅读和测试我发现

Specifying custom User model (extends AbstractUser) doesn't work

As the error message says -- you need to update the relation to point at settings.AUTH_USER_MODEL. The second error ("Model has been swapped out…") is a side effect of the fact that you're directly referencing the User model. Once you change the ForieignKey references, this third error will go away. We've done everything we can to ensure a smooth transition to the new User model, but it can't be completely transparent. App writers will need to update their apps to be 1.5 compatible. Essentially, a Django 1.4 app won't be 100% compatible with Django 1.5 if it contains a hard-coded foreign key reference to User. Please, could you give me more examples?

Django/Python: Update the relation to point at settings.AUTH_USER_MODEL

in settings_example.py you have AUTH_USER_MODEL = 'users.User'. However you are using an app - menu.bookmark - that has a relation to django.contrib.auth.User - you can't have both. Setting AUTH_USER_MODEL means that you are replacing the built-in Django user model with your own. See http://procrastinatingdev.com/django/using-configurable-user-models-in-django-1-5/ for details.

但我不明白我该如何解决这个问题。

我需要什么:

-用户链接到学院类(一个学院->更多用户)

-用户或机构可以有不同的权限,看到不同的django cms页面/插件。

-用户的更多字段。

子类 AbstractUser 是否正确?

如何解决“换出”错误?

我应该创建类似于 OpenTreeMap Code 的东西

这段代码不是弃用了吗?

谢谢!

最佳答案

有一个非常简单的解决方案。只需要在导入 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

关于django 1.5 扩展默认用户模型或替换它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16605453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com