From c43c5c1e10d0413753abd13f80f6f55337133d5a Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Tue, 4 Feb 2020 00:40:40 +0100 Subject: [PATCH] Move QSO no validation into model --- contest/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contest/models.py b/contest/models.py index fecaa4e..404772e 100644 --- a/contest/models.py +++ b/contest/models.py @@ -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)