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:
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user