Generateurv2/backend/api/users/models.py

36 lines
954 B
Python
Raw Normal View History

2022-06-11 23:39:03 +02:00
import random
import string
from uuid import uuid4
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
from django.db import models
def generate_unique_code():
length = 10
while True:
code = ''.join(random.choices(string.ascii_uppercase, k=length))
if CustomUser.objects.filter(id_code=code).count() == 0:
break
return code
def generate_unique_uuid():
while True:
code = str(uuid4())
if CustomUser.objects.filter(clientId=code).count() == 0:
break
return code
class CustomUser(AbstractUser):
# Any extra fields would go here
registeredExos = models.ManyToManyField("exercices.Exercice")
id_code = models.CharField(default=generate_unique_code, max_length=50, unique = True)
clientId = models.CharField(default=generate_unique_uuid, max_length=50, )
def __str__(self):
return self.email