custom django user model code example

Example 1: django user fields

# Django User Model Fields
username
first_name
last_name
email
password
groups
user_permissions
is_staff
is_active
is_superuser
last_login
date_joined

Example 2: import abstractuser

from django.contrib.auth.models import AbstractUser

Example 3: django create user

from django.contrib.auth.models import User
user = User.objects.create_user(value['USERNAME'], value['EMAIL'], value['PASSWORD'])
user.first_name = value['NAME']
user.last_name = value['SURNAME']
user.save()

Example 4: django customize the user model

from django.contrib.auth.models import User

class Employee(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    department = models.CharField(max_length=100)

Tags:

Misc Example