I am new to django and from a tutorial video, in the model.py file for the profile app, he created an instance of the User model in a one-to-one relationship with the profile model class like so:
`
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, blank=True, null=True)
I understand that he created a one-to-one relationship with the profile model and the User model by creating an instance of the User model in the class.
I am trying to achieve this with AbstractUser as well.
I tried to do the same thing like so:
from django.contrib.auth.models import AbstractUser
class Blogger(models.Model):
user = models.OneToOneField(AbstractUser, blank=True, null=True)
In the settings.py, I have connected the PostGresSql database like so:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'bookandreviews',
'USER': 'postgres',
'HOST': 'localhost',
'PASSWORD': '2030',
'PORT': '5432'
}
}
I ran py manage.py runserver
and I got this error:
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
users.Bloggers.user: (fields.E300) Field defines a relation with model 'AbstractUser', which is either not installed, or is abstract.
users.Bloggers.user: (fields.E307) The field users.Bloggers.user was declared
with a lazy reference to 'auth.abstractuser', but app 'auth' doesn't provide model 'abstractuser'.
I don't understand it. So I tried to add an auth_user_model, like so:
AUTH_USER_MODEL = 'users.Bloggers'
And I immediately got this issue:
AttributeError: type object 'Bloggers' has no attribute 'REQUIRED_FIELDS'
** Please can anyone help me understand all of this and also, is it possible to instantiate the AbstractUser model?**