Z
Z
zelsky2016-01-12 00:30:23
Django
zelsky, 2016-01-12 00:30:23

Creating a custom Django user?

Created aap. Connected, made migration.
But when I send from the shell

q = CustomUser.create_user('Pol',password='123123123aa')

I get that
AttributeError: type object 'CustomUser' has no attribute 'create_user'

I can't figure out how to expand the user model into several fields, with the ability to create and save them. So I will send all the parameters from the form, but how to save them in the database through such a model? ppc shorter
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')

djangosimple.blogspot.com/2014/05/user-django.html

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2016-01-12
@zelsky

deliro.ru first post.

A
Alexander Pinkevich, 2016-01-12
@pinkevich

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 question

Ask a Question

731 491 924 answers to any question