我创建了一个模型 CustomerRegistration 并在其中添加了字段,我与用户模型建立了关系并将其注册到 admin.py 文件中。当我转到 Django 默认管理面板并注册客户时,它给出了一个错误。'''TypeError at /admin/customer/customerregistration/add/ str返回了非字符串(用户类型)'''。我不知道出了什么问题。这是我的模型.pyfrom django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixinfrom django.db import modelsfrom django.utils import timezone# Create Your Models Here.class UserManager(BaseUserManager): def _create_user(self, username, password, is_staff, is_superuser, **extra_fields): if not username: raise ValueError('Users must have an username address') now = timezone.now() username = self.model.normalize_username(username) user = self.model( username=username, is_staff=is_staff, is_active=True, is_superuser=is_superuser, last_login=now, date_joined=now, **extra_fields ) user.set_password(password) user.save(using=self._db) return user def create_user(self, username=None, password=None, **extra_fields): return self._create_user( username, password, False, False, **extra_fields) def create_superuser(self, username, password, **extra_fields): user = self._create_user(username, password, True, True, **extra_fields) user.save(using=self._db) return userclass User(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=254,unique=True) name = models.CharField(max_length=254, null=True) email = models.EmailField(max_length=254, null=True) is_staff = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) is_active = models.BooleanField(default=True) is_service = models.BooleanField(default=False) is_customer = models.BooleanField(default=False) is_admin = models.BooleanField(default=False)
添加回答
举报
0/150
提交
取消