Answer the question
In order to leave comments, you need to log in
Creating a custom Django user?
Created aap. Connected, made migration.
But when I send from the shell
q = CustomUser.create_user('Pol',password='123123123aa')
AttributeError: type object 'CustomUser' has no attribute 'create_user'
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
JUSER = 'juser'
VLASNUK = 'vlasnuk'
role_choice = (
(JUSER , 'juser'),
(VLASNUK, 'vlasnuk'),
)
class CustomUser(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
role = models.CharField(max_length=100,choices=role_choice,default='juser')
Answer the question
In order to leave comments, you need to log in
create_user is in the User model (in the manager), but yours is not.
If you want to create a new user, then use User.objects.create_user(...).
+ The CustomUser model object itself will not be created, it must be explicitly created:
# Example
user = User.objects.get(pk=1) # or User.objects.create_user(...)
custom_user = CustomUser.objects.create(user=user, role=<your role>)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question