Редактировать: + Patient
Пока я проверял свой код, я заметил, что некоторые модели имеют свойство «пароль» в виде столбца БД в PostgreSQL и что эти модели не имеют этого атрибута, единственныйсвязь между атрибутом «пароль» и таблицей заключается в том, что модель таблицы имеет FK, указывающий на модель, которая является расширением AbstractBaseUser.
django = ">=2.1.0"
djangorestframework = ">=3.9.2"
flake8 = ">=3.6.0,<3.7.0"
autopep8 = "*"
psycopg2 = "<2.8.0,>=2.7.5"
django-organizations = "==1.1.2"
django-countries = "*"
[requires]
python_version = "3.7"
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, \
PermissionsMixin
import datetime
from django.core.validators import MaxValueValidator
from django_countries.fields import CountryField
# Create your models here.
class UserManager(BaseUserManager):
def create_user(self, email, password = None, ** kwargs):
""
"Creates and saves a new User"
""
if not email:
raise ValueError('Users must have an email address')
user = self.model(email = self.normalize_email(email), ** kwargs)
user.set_password(password)
user.is_staff = False
user.is_active = True
user.is_doctor = False
user.save(using = self._db)
return user
def create_superuser(self, email, password, ** kwargs):
""
"Creates and saves a new super user"
""
user = self.create_user(email, password, ** kwargs)
user.is_staff = False
user.is_active = True
user.is_doctor = False
user.is_superuser = True
user.save(using = self._db)
return user
class User(AbstractBaseUser, PermissionsMixin):
""
"Custom user model that supports using email instead of username"
""
email = models.EmailField(max_length = 254, unique = True)
firstName = models.CharField(max_length = 30)
middleName = models.CharField(max_length = 30, blank = True)
firstSurname = models.CharField(max_length = 50)
lastSurname = models.CharField(max_length = 50, blank = True)
passwordHint = models.CharField(max_length = 20, blank = True, null = True)
creationDate = models.DateField(
default = datetime.date.today, blank = False, null = False)
lastLoginDate = models.DateField(
blank = True, null = True)
lastPasswordResetDate = models.DateField(blank = True, null = True)
is_active = models.BooleanField(
default = True)
is_staff = models.BooleanField(
default = False)
is_doctor = models.BooleanField(
default = False)
externalUserCode = models.CharField(max_length = 20, blank = True, null = True)
objects = UserManager()
USERNAME_FIELD = 'email'
class Doctor(AbstractBaseUser):
"""Custom user that has the information of the doctors"""
doctorID = models.OneToOneField(
User, on_delete=models.CASCADE, primary_key=True)
specialtyID = models.ManyToManyField(DoctorSpecialties)
identificationTypeID = models.ForeignKey('generic.IdentificationType',
on_delete=models.CASCADE)
identificationTypeNumber = models.PositiveIntegerField(
validators=[MaxValueValidator(9999999999)])
class Patient(AbstractBaseUser):
"""Custom user that has the information of the patient"""
id = models.AutoField(primary_key=True)
patient = models.ForeignKey(User, on_delete=models.CASCADE)
identificationType = models.ForeignKey('genericWS.IdentificationType',
on_delete=models.CASCADE)
identificationNumber = models.CharField(max_length=30, null=False)
patientAddress = models.CharField(max_length=30, null=False)
Проблема заключается в том, что у меня есть имя столбца «пароль» длятаблицы public.noteapp_patient и public.noteapp_doctor, которые я не знаю точно, почему они там есть, поскольку я не объявляю это свойство в модели.