我的问题似乎与this one类似,但答案和解释似乎不够,所以我要继续使用我自己理解的自定义auth_user_model问题。我的app / users / model.py是这样的:
from django.contrib.auth.models import (
BaseUserManager,AbstractBaseUser)
from django.contrib.auth.models import PermissionsMixin
from django.db import models
class MyUserManager(BaseUserManager):
def create_user(self, email, password,name=''):
"""
Creates and saves a User with the given email, password
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
name=name
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email,password,name=''):
user = self.create_user(email,name=name,password=password)
user.is_admin = True
user.is_active = True
user.is_superuser = True
user.save(using=self._db)
return user
class MyUser(AbstractBaseUser,PermissionsMixin):
email = models.EmailField(
verbose_name='email',
max_length=255,
unique=True,
)
name = models.CharField(max_length=255,blank=True,default='')
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'email'
#REQUIRED_FIELDS = ['name']
def get_full_name(self):
return self.name if self.name else self.email
def get_short_name(self):
return self.email
def __unicode__(self):
return self.email
@property
def is_staff(self):
return self.is_superuser
我的堆栈跟踪如下:
Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/.virtualenvs/project/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 50, in execute
return super(Command, self).execute(*args, **options)
File "/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/.virtualenvs/project/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 149, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
AttributeError: 'MyUserManager' object has no attribute 'create_superuser'
我不能为我的生活弄清楚为什么会出现这个错误。我正在使用带有Python 2.7.11的Django 1.9.1和pydanny的cookiecutter django模块。相关的已安装应用包括djstripe和allauth。 Djstripe主要在这些条件下工作,但我无法创建超级用户或登录管理区域。
在这里不知所措,所以我希望Django jedi可以引导我朝着更好的方向前进,并提供某种解释。感谢