feat: added generate_random_color function for color field in model, default value set
This commit is contained in:
parent
23233c15e9
commit
144ab73dc8
1 changed files with 5 additions and 2 deletions
|
|
@ -1,10 +1,13 @@
|
||||||
import uuid
|
import uuid, random
|
||||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, Group, Permission
|
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, Group, Permission
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
def generate_uuid_without_dashes():
|
def generate_uuid_without_dashes():
|
||||||
return uuid.uuid4().hex
|
return uuid.uuid4().hex
|
||||||
|
|
||||||
|
def generate_random_color():
|
||||||
|
return "#" + "".join(random.choices("0123456789ABCDEF", k=6))
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
def create_user(self, email, first_name, password=None):
|
def create_user(self, email, first_name, password=None):
|
||||||
if not email:
|
if not email:
|
||||||
|
|
@ -34,7 +37,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||||
email = models.EmailField(unique=True)
|
email = models.EmailField(unique=True)
|
||||||
phone = models.CharField(max_length=20, blank=True, null=True)
|
phone = models.CharField(max_length=20, blank=True, null=True)
|
||||||
initials = models.CharField(max_length=10, blank=True)
|
initials = models.CharField(max_length=10, blank=True)
|
||||||
color = models.CharField(max_length=20, blank=True)
|
color = models.CharField(max_length=20, blank=True, default=generate_random_color)
|
||||||
is_online = models.BooleanField(default=False)
|
is_online = models.BooleanField(default=False)
|
||||||
is_contact_only = models.BooleanField(default=False)
|
is_contact_only = models.BooleanField(default=False)
|
||||||
last_login = models.DateTimeField(blank=True, null=True)
|
last_login = models.DateTimeField(blank=True, null=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue