mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
guardian/student + ajout de la possibilité de créer un guardian pour un student + tri chrologique
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
from django.contrib.auth.models import AbstractUser
|
|
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.core.validators import EmailValidator
|
|
from Establishment.models import Establishment
|
|
|
|
class Profile(AbstractUser):
|
|
email = models.EmailField(max_length=255, unique=True, default="", validators=[EmailValidator()])
|
|
|
|
USERNAME_FIELD = 'email'
|
|
REQUIRED_FIELDS = ('password', )
|
|
|
|
code = models.CharField(max_length=200, default="", blank=True)
|
|
datePeremption = models.CharField(max_length=200, default="", blank=True)
|
|
|
|
def __str__(self):
|
|
return self.email
|
|
|
|
class ProfileRole(models.Model):
|
|
class RoleType(models.IntegerChoices):
|
|
PROFIL_UNDEFINED = -1, _('NON DEFINI')
|
|
PROFIL_ECOLE = 0, _('ECOLE')
|
|
PROFIL_ADMIN = 1, _('ADMIN')
|
|
PROFIL_PARENT = 2, _('PARENT')
|
|
|
|
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='roles')
|
|
role_type = models.IntegerField(choices=RoleType.choices, default=RoleType.PROFIL_UNDEFINED)
|
|
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='profile_roles')
|
|
is_active = models.BooleanField(default=False)
|
|
updated_date = models.DateTimeField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return f"{self.profile.email} - {self.get_role_type_display()} - {self.establishment.name}" |