forked from DGNum/gestioCOF
Events: more validation & uniqueness constraints
This commit is contained in:
parent
d7d4d73af3
commit
5a0cf58d8a
1 changed files with 14 additions and 0 deletions
|
@ -29,6 +29,7 @@ option in this case).
|
|||
"""
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -73,6 +74,7 @@ class Option(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _("option d'événement")
|
||||
verbose_name_plural = _("options d'événement")
|
||||
unique_together = [["event", "name"]]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -87,6 +89,7 @@ class OptionChoice(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _("choix d'option d'événement")
|
||||
verbose_name_plural = _("choix d'option d'événement")
|
||||
unique_together = [["option", "choice"]]
|
||||
|
||||
def __str__(self):
|
||||
return self.choice
|
||||
|
@ -114,6 +117,9 @@ class ExtraField(models.Model):
|
|||
name = models.CharField(_("champ d'événement supplémentaire"), max_length=200)
|
||||
field_type = models.CharField(_("type de champ"), max_length=9, choices=FIELD_TYPE)
|
||||
|
||||
class Meta:
|
||||
unique_together = [["event", "name"]]
|
||||
|
||||
|
||||
class ExtraFieldContent(models.Model):
|
||||
"""Value entered in an extra field."""
|
||||
|
@ -124,9 +130,16 @@ class ExtraFieldContent(models.Model):
|
|||
)
|
||||
content = models.TextField(_("contenu du champ"))
|
||||
|
||||
def clean(self):
|
||||
if self.registration.event != self.field.event:
|
||||
raise ValidationError(
|
||||
_("Inscription et champ texte incohérents pour ce commentaire")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("contenu d'un champ événement supplémentaire")
|
||||
verbose_name_plural = _("contenus d'un champ événement supplémentaire")
|
||||
unique_together = [["field", "registration"]]
|
||||
|
||||
def __str__(self):
|
||||
max_length = 50
|
||||
|
@ -146,6 +159,7 @@ class Registration(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _("inscription à un événement")
|
||||
verbose_name_plural = _("inscriptions à un événement")
|
||||
unique_together = [["event", "user"]]
|
||||
|
||||
def __str__(self):
|
||||
return "inscription de {} à {}".format(self.user, self.event)
|
||||
|
|
Loading…
Reference in a new issue