annuaire-eleves/fiches/models.py

96 lines
3.1 KiB
Python
Raw Normal View History

2019-02-11 23:51:38 +01:00
from django.contrib.auth.models import User
2021-01-28 01:04:10 +01:00
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
2019-02-11 22:52:48 +01:00
2019-02-11 23:51:38 +01:00
class Profile(models.Model):
2019-02-18 21:47:03 +01:00
user = models.OneToOneField(
2020-01-27 19:58:25 +01:00
User,
on_delete=models.CASCADE,
verbose_name=_("utilisateur"),
related_name="profile",
2019-02-18 21:47:03 +01:00
)
full_name = models.CharField(max_length=1023, verbose_name=_("nom"))
2019-02-18 22:03:38 +01:00
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)")
)
2019-02-18 22:03:38 +01:00
picture = models.ImageField(
blank=True, upload_to="picture", verbose_name=_("photo")
)
2019-02-18 21:47:03 +01:00
department = models.ManyToManyField("Department", verbose_name=_("département"))
promotion = models.IntegerField(
validators=[MinValueValidator(1980)], verbose_name=_("promotion")
)
2020-11-13 11:39:28 +01:00
birth_date = models.DateField(
blank=True, null=True, verbose_name=_("date de naissance")
)
2019-02-18 22:03:38 +01:00
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 ?")
)
2020-01-27 19:58:25 +01:00
2019-04-08 21:47:50 +02:00
def __str__(self):
return self.full_name
2019-02-18 21:47:03 +01:00
def birthday(self):
2020-02-08 14:10:14 +01:00
return self.birth_date.strftime("%d%m")
2019-02-11 23:51:38 +01:00
class Department(models.Model):
2020-11-13 11:39:28 +01:00
name = models.CharField(
max_length=255, verbose_name=_("nom du département"), unique=True
)
2020-01-27 19:58:25 +01:00
2019-04-08 21:47:50 +02:00
def __str__(self):
return self.name
2019-02-18 21:47:03 +01:00
class Phone(models.Model):
2019-04-08 21:47:50 +02:00
profile = models.ForeignKey(
2020-09-17 15:46:16 +02:00
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
2019-02-18 21:47:03 +01:00
)
2020-01-09 00:07:59 +01:00
name = models.CharField(max_length=255, verbose_name=_("type"))
2019-02-18 21:47:03 +01:00
number = models.CharField(max_length=1023, verbose_name=_("numéro"))
2020-01-27 19:58:25 +01:00
2019-04-08 21:47:50 +02:00
def __str__(self):
return "{} : {}".format(self.name, self.number)
2019-02-18 21:47:03 +01:00
class Social(models.Model):
2019-04-08 21:47:50 +02:00
profile = models.ForeignKey(
2019-02-18 21:47:03 +01:00
Profile, on_delete=models.CASCADE, verbose_name=_("profil")
)
2020-01-09 00:07:59 +01:00
name = models.CharField(max_length=255, verbose_name=_("type"))
2019-02-18 21:47:03 +01:00
content = models.CharField(max_length=1023, verbose_name=_("contenu"))
2020-01-27 19:58:25 +01:00
2020-01-09 00:07:59 +01:00
def __str__(self):
return "{} : {}".format(self.name, self.content)
2020-01-27 19:58:25 +01:00
2020-01-09 00:07:59 +01:00
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"))
2020-01-27 19:58:25 +01:00
2020-01-09 00:07:59 +01:00
def __str__(self):
return "{} : {}".format(self.name, self.mail)
2020-01-27 19:58:25 +01:00
2020-01-09 00:07:59 +01:00
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.TextField(verbose_name=_("adresse"))
2020-01-27 19:58:25 +01:00
2019-04-08 21:47:50 +02:00
def __str__(self):
2020-01-27 19:58:25 +01:00
return "{} : {}".format(self.name, self.content)