Skip to content

Instantly share code, notes, and snippets.

@BrockHerion
Last active November 5, 2020 04:32
Show Gist options
  • Save BrockHerion/efc50098f185c135cfc2ff18ee5258af to your computer and use it in GitHub Desktop.
Save BrockHerion/efc50098f185c135cfc2ff18ee5258af to your computer and use it in GitHub Desktop.
Create user fields in models.py
import uuid
from django.db import models
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils import timezone
from .managers import CustomUserManager
# Create your models here.
class User(AbstractBaseUser, PermissionsMixin):
# Roles created here
uid = models.UUIDField(unique=True, editable=False, default=uuid.uuid4, verbose_name='Public identifier')
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=50, blank=True)
role = models.PositiveSmallIntegerField(choices=ROLE_CHOICES, blank=True, null=True, default=3)
date_joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_date = models.DateTimeField(default=timezone.now)
modified_date = models.DateTimeField(default=timezone.now)
created_by = models.EmailField()
modified_by = models.EmailField()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def __str__(self):
return self.email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment