[英]Django error: AttributeError at 'Manager' object has no attribute 'create_user'
models.py: models.py:
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
class UserManager(BaseUserManager):
# code
def create_user(self, uid, pass):
# code
class user(AbstractBaseUser, PermissionsMixin):
# code
objects = UserManager()
# code
class appUser(user):
# code
views.py views.py
from projectname.app.models import appUser
def index_view(request):
# code
appUser.objects.create_user(uid_variable, pass_variable)
# code
settings.py settings.py
#code
INSTALLED_APPS = (
#code
'projectname.app',
)
AUTH_USER_MODEL = 'app.appUser'
#code
When I am trying to call a create-user method in view this exception appears. 当我尝试在视图中调用create-user方法时,会出现此异常。 What am I doing wrong?
我究竟做错了什么?
Your appUser
is a subclass of user
. 您的
appUser
是user
的子类。 If user
is not an abstract base class, then appUser
will not inherit the manager, and you will need to redeclare it. 如果
user
不是抽象基类,则appUser
将不会继承管理器,因此您需要重新声明它。
class appUser(user):
objects = UserManager()
Managers defined on non-abstract base classes are not inherited by child classes.
在非抽象基类上定义的管理器不会由子类继承。 If you want to reuse a manager from a non-abstract base, redeclare it explicitly on the child class.
如果要从非抽象基础上重用管理器,请在子类上明确地重新声明它。 These sorts of managers are likely to be fairly specific to the class they are defined on, so inheriting them can often lead to unexpected results (particularly as far as the default manager goes).
这些类型的管理器可能非常特定于它们所定义的类,因此继承它们通常会导致意外的结果(尤其是默认管理器使用的结果)。 Therefore, they aren't passed onto child classes.
因此,它们不会传递给子类。
Having your appUser
model subclass user
is complex, you might encounter other difficulties. 让
appUser
模型子类user
很复杂,您可能会遇到其他困难。 I would avoid it if possible, or at least make user
abstract. 如果可能的话,我会避免它,或者至少使
user
抽象化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.