36 lines
954 B
Python
36 lines
954 B
Python
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 |