1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-07-05 07:14:08 +02:00

Create and join teams forms

This commit is contained in:
Yohann D'ANELLO
2020-09-23 23:20:44 +02:00
parent 369c9e2fa2
commit cce3a0a7df
7 changed files with 69 additions and 13 deletions

View File

@ -1,6 +1,7 @@
from django.core.validators import RegexValidator
from django.db import models
from django.db.models import Index
from django.utils.crypto import get_random_string
from django.utils.translation import gettext_lazy as _
@ -14,7 +15,7 @@ class Team(models.Model):
trigram = models.CharField(
max_length=3,
verbose_name=_("trigram"),
help_text=_("The trigram must be composed of 3 uppercase letters."),
help_text=_("The trigram must be composed of three uppercase letters."),
unique=True,
validators=[RegexValidator("[A-Z]{3}")],
)
@ -31,6 +32,11 @@ class Team(models.Model):
default=False,
)
def save(self, *args, **kwargs):
if not self.access_code:
self.access_code = get_random_string(6)
return super().save(*args, **kwargs)
def __str__(self):
return _("Team {name} ({trigram})").format(name=self.name, trigram=self.trigram)