Move QSO no validation into model

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

View File

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