Move QSO no validation into model

This commit is contained in:
Sebastian Lohff 2020-02-04 00:40:40 +01:00
parent a7f303e651
commit 3c6936ba44
1 changed files with 5 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import datetime
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import RegexValidator
from django.core.validators import RegexValidator, MinValueValidator, MaxValueValidator
from django.db.models import Q, signals
from .validators import CallUsernameValidator
@ -146,6 +146,7 @@ class Frequency(models.Model):
return "Channel %s: %s MHz" % (self.channel, self.qrg)
class QSO(models.Model):
MAX_NO_VALUE = 1000000
reportValidator = RegexValidator("[1-5][1-9]")
class Meta:
@ -162,8 +163,9 @@ class QSO(models.Model):
reportTX = models.CharField(max_length=7, default=59, verbose_name='RS-S', validators=[reportValidator])
reportRX = models.CharField(max_length=7, default=59, verbose_name='RS-R', validators=[reportValidator])
ownNo = models.IntegerField(verbose_name='No')
otherNo = models.IntegerField(verbose_name='No-R', null=True, blank=True)
ownNo = models.IntegerField(verbose_name='No', validators=[MinValueValidator(1), MaxValueValidator(MAX_NO_VALUE)])
otherNo = models.IntegerField(verbose_name='No-R', null=True, blank=True,
validators=[MinValueValidator(1), MaxValueValidator(MAX_NO_VALUE)])
refStr = models.CharField(max_length=20, verbose_name="EXC")
ref = models.ForeignKey(Reference, models.SET_NULL, null=True, blank=True)