TypeError:create_superuser()缺少1个必需的位置参数:“ name”

时间:2018-06-26 13:21:38

标签: python django django-models django-rest-framework

即使在我的models.py文件中的create_superuser函数中添加了名称之后,我仍然遇到以下错误

from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
# Create your models here.
class UserProfileManager(BaseUserManager):
    def create_user(self,email,name,password=None):
        if not email:
            raise ValueError("email is required")
        email=self.normalize_email(email)
        user=self.model(email=email,name=name)

        user.set_password(password)
        user.save(using=self._db)
        return user
    def create_superuser(self,email,name,password):
        """creates new super user with details """

        user=self.create_user(email,name,password)
        user.is_superuser=True
        user.is_staff=True
        user.save(using=self._db)
        return user

class UserProfiles(AbstractBaseUser,PermissionsMixin):
    email=models.EmailField(max_length=255,unique=True)
    name=models.CharField(max_length=255)
    is_active=models.BooleanField(default=True)
    is_staff=models.BooleanField(default=False)
    objects=UserProfileManager()

    USERNAME_FIELD='email'
    REQUIRED_FIELD=['name']
    def get_fullname(self):
        return self.name
    def get_shortname(self):
        return self.name
    def __str__ (self):
        return self.email

并且当我尝试运行python manage.py createsuperuser命令时出现以下错误

TypeError: create_superuser() missing 1 required positional argument: 'name'

我不知道我的错误在哪里?

任何帮助都值得赞赏 预先感谢

0 个答案:

没有答案