arrowcounter/score/models.py
Claudio Maggioni (maggicl) b5a133a3c2 Added models to score app
2019-08-07 12:44:12 +02:00

41 lines
1.5 KiB
Python

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _
from django.core.validators import RegexValidator, MaxValueValidator, \
MaxLengthValidator
class Score(models.Model):
TARGETS = [
('TR', _('40/60/80/120cm Target')),
('HF', _('H&F target'))
]
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE
)
ends = models.PositiveSmallIntegerField(_('Number of ends in this score'),
validators=[MaxValueValidator(24)])
arrows_per_end = models.PositiveSmallIntegerField(
_('Number of arrows per end'), validators=[MaxValueValidator(12)])
date = models.DateField(_('Date of the score'))
notes = models.TextField(_('Additional notes'),
validators=[MaxLengthValidator(500)])
target = models.CharField(_('Type of target'), max_length=2,
choices=TARGETS)
class ScoreRow(models.Model):
class Meta:
unique_togheter = ('score', 'end_number')
score = models.ForeignKey(Score, on_delete=models.CASCADE)
arrow_list = models.CharField(_('Comma separated list of arrow scores'),
max_length=36,
validators=[RegexValidator(regex="^(\d|10)(,(\d|10)){2,11}$",
message=_("Value given is not a valid score row"))])
end_number = models.PositiveSmallIntegerField(_('End number'),
validators=[MaxValueValidator(24)])