annuaire-eleves/fiches/models.py

95 lines
3.1 KiB
Python

from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
class Profile(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
verbose_name=_("utilisateur"),
related_name="profile",
)
full_name = models.CharField(max_length=1023, verbose_name=_("nom"))
nickname = models.CharField(blank=True, max_length=1023, verbose_name=_("surnom"))
pronoun = models.CharField(
blank=True, max_length=1023, verbose_name=_("pronom(s) utilisé(s)")
)
picture = models.ImageField(
blank=True, upload_to="picture", verbose_name=_("photo")
)
department = models.ManyToManyField("Department", verbose_name=_("département"))
promotion = models.IntegerField(
validators=[MinValueValidator(1980)], verbose_name=_("promotion")
)
birth_date = models.DateField(
blank=True, null=True, verbose_name=_("date de naissance")
)
thurne = models.CharField(blank=True, max_length=100, verbose_name=_("thurne"))
text_field = models.TextField(blank=True, verbose_name=_("champ libre"))
printing = models.BooleanField(
default=False, verbose_name=_("apparaître sur l'annuaire papier ?")
)
keep_me = models.BooleanField(
default=False, verbose_name=_("conserver la fiche annuaire ?")
)
def __str__(self):
return self.full_name
def birthday(self):
return self.birth_date.strftime("%d%m")
class Department(models.Model):
name = models.CharField(
max_length=255, verbose_name=_("nom du département"), unique=True
)
def __str__(self):
return self.name
class Phone(models.Model):
profile = models.ForeignKey(
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
)
name = models.CharField(max_length=255, verbose_name=_("type"))
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
def __str__(self):
return "{} : {}".format(self.name, self.number)
class Social(models.Model):
profile = models.ForeignKey(
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
)
name = models.CharField(max_length=255, verbose_name=_("type"))
content = models.CharField(max_length=1023, verbose_name=_("contenu"))
def __str__(self):
return "{} : {}".format(self.name, self.content)
class Mail(models.Model):
profile = models.ForeignKey(
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
)
name = models.CharField(max_length=255, verbose_name=_("type"))
mail = models.CharField(max_length=1023, verbose_name=_("adresse mail"))
def __str__(self):
return "{} : {}".format(self.name, self.mail)
class Address(models.Model):
profile = models.ForeignKey(
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
)
name = models.CharField(max_length=255, verbose_name=_("type"))
content = models.CharField(max_length=1023, verbose_name=_("adresse"))
def __str__(self):
return "{} : {}".format(self.name, self.content)