Я создал модель CustomerRegistration и добавил в нее поля, установил связь с моделями пользователей и зарегистрировал ее в файле admin.py. когда я go перехожу в панель администратора Django по умолчанию и регистрирую клиента, выдается ошибка. ) '' '. Я не знаю, что не так.
вот мой models.py
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.db import models
from 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 user
class 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)
id_user_type = models.OneToOneField('Role', null=True, on_delete=models.CASCADE, related_name='usertype')
last_login = models.DateTimeField(null=True, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'username'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
def get_absolute_url(self):
return "/users/%i/" % (self.pk)
def get_username(self):
return self.username
class CustomerRegistration(models.Model):
name = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
date_of_birth = models.DateTimeField(null=True)
country_id = models.ForeignKey('accounts.Country', null=True, on_delete=models.CASCADE, related_name='Country')
state_id = models.ForeignKey('accounts.State', null=True, on_delete=models.CASCADE, related_name='State')
cities_id = models.ForeignKey('accounts.City', null=True, on_delete=models.CASCADE, related_name='city')
refernce_by_person_name = models.CharField(max_length=254, null=True)
refernce_by_person_contact_no = models.IntegerField(null=True)
phone_no = models.IntegerField(null=True)
alternate_no = models.IntegerField(null=True)
hobbies = models.CharField(max_length=254)
def __str__(self):
return self.name
I