2018-01-14 12:19:11 +00:00
|
|
|
from django.db import models
|
2018-03-01 10:25:34 +00:00
|
|
|
from django.contrib.auth.models import User, Group, Permission
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2018-01-31 09:15:51 +00:00
|
|
|
from django.db.models.signals import post_save
|
2018-02-28 20:25:44 +00:00
|
|
|
from django.urls import reverse
|
2018-01-31 09:15:51 +00:00
|
|
|
from django.dispatch import receiver
|
2018-03-02 08:33:37 +00:00
|
|
|
from django.core import validators
|
2018-01-14 12:19:11 +00:00
|
|
|
|
2018-01-31 09:15:51 +00:00
|
|
|
|
2018-03-08 22:16:03 +00:00
|
|
|
def get_upload_to(instance, filename):
|
|
|
|
return "static/media/"+instance.name+"/"+filename
|
|
|
|
|
|
|
|
|
|
|
|
class School(models.Model):
|
2018-01-31 09:15:51 +00:00
|
|
|
"""Ajoute un champ pour distinguer les groupes écoles des autres."""
|
2018-03-09 10:44:49 +00:00
|
|
|
name = models.CharField(
|
|
|
|
verbose_name="Nom de l'école",
|
|
|
|
max_length=255,
|
|
|
|
default=""
|
|
|
|
)
|
2018-03-08 22:16:03 +00:00
|
|
|
admin = models.OneToOneField(
|
|
|
|
User,
|
|
|
|
verbose_name="Administrateur de l'école",
|
|
|
|
null=True,
|
2018-03-01 10:25:34 +00:00
|
|
|
on_delete=models.SET_NULL,
|
2018-02-28 20:25:44 +00:00
|
|
|
)
|
2018-03-02 08:33:37 +00:00
|
|
|
phone = models.CharField(
|
|
|
|
max_length=10,
|
|
|
|
help_text="Visible uniquement des administrateurs",
|
|
|
|
verbose_name="Numéro de téléphone pour contacter le responsable des productions",
|
|
|
|
blank=False,
|
|
|
|
null=True,
|
|
|
|
validators=[
|
|
|
|
validators.RegexValidator('^[0-9]{10}$',
|
|
|
|
"Veuillez entrer un numéro à 10 chiffres."),
|
|
|
|
]
|
|
|
|
)
|
2018-03-08 22:16:03 +00:00
|
|
|
logo = models.ImageField(
|
|
|
|
upload_to=get_upload_to,
|
|
|
|
verbose_name="Logo à utiliser pour représenter l'école",
|
|
|
|
null=True,
|
|
|
|
blank=False,
|
|
|
|
)
|
2018-03-08 23:53:38 +00:00
|
|
|
validated = models.BooleanField(
|
|
|
|
verbose_name="Inscription validé.",
|
|
|
|
default=False
|
|
|
|
)
|
2018-03-08 22:16:03 +00:00
|
|
|
first_name_j1 = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name="Prénom juré n°1"
|
|
|
|
)
|
|
|
|
last_name_j1 = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name="Nom juré n°1"
|
|
|
|
)
|
|
|
|
phone_j1 = models.CharField(
|
|
|
|
max_length=10,
|
|
|
|
help_text="Visible uniquement des administrateurs",
|
|
|
|
verbose_name="Numéro de téléphone juré n°1",
|
|
|
|
blank=False,
|
|
|
|
null=True,
|
|
|
|
validators=[
|
|
|
|
validators.RegexValidator('^[0-9]{10}$',
|
|
|
|
"Veuillez entrer un numéro à 10 chiffres."),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
mail_j1 = models.EmailField(verbose_name="Email juré n°1")
|
|
|
|
first_name_j2 = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name="Prénom juré n°2"
|
|
|
|
)
|
|
|
|
last_name_j2 = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name="Nom juré n°2"
|
|
|
|
)
|
|
|
|
phone_j2 = models.CharField(
|
|
|
|
max_length=10,
|
|
|
|
help_text="Visible uniquement des administrateurs",
|
|
|
|
verbose_name="Numéro de téléphone juré n°2",
|
|
|
|
blank=False,
|
|
|
|
null=True,
|
|
|
|
validators=[
|
|
|
|
validators.RegexValidator('^[0-9]{10}$',
|
|
|
|
"Veuillez entrer un numéro à 10 chiffres."),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
mail_j2 = models.EmailField(verbose_name="Email juré n°2")
|
|
|
|
|
2018-01-31 09:15:51 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2018-03-09 10:44:49 +00:00
|
|
|
return self.name
|
2018-01-31 09:15:51 +00:00
|
|
|
|
2018-02-28 20:25:44 +00:00
|
|
|
def get_absolute_url(self):
|
2018-03-09 10:44:49 +00:00
|
|
|
return reverse("users:school", kwargs={'pk':self.pk})
|
2018-03-02 09:02:54 +00:00
|
|
|
|
|
|
|
def number_of_categories(self):
|
|
|
|
return self.content_set.values('category').distinct().count()
|
2018-01-31 09:15:51 +00:00
|
|
|
|