from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import AbstractUser from django.core.validators import RegexValidator from .validators import CallUsernameValidator class Contest(models.Model): name = models.CharField(max_length=20) shortName = models.CharField(max_length=20, unique=True) callQrg = models.ForeignKey("Frequency", models.SET_NULL, null=True, blank=True) def __str__(self): return self.name class Reference(models.Model): name = models.CharField(max_length=20, unique=True, db_index=True) description = models.TextField() def __str__(self): return self.name class ShadowCall(models.Model): username = models.CharField(max_length=20, unique=True, db_index=True, validators=[CallUsernameValidator()]) ref = models.ForeignKey(Reference, models.SET_NULL,null=True, blank=True) def __str__(self): return self.username class User(AbstractUser): ref = models.ForeignKey(Reference, models.SET_NULL,null=True, blank=True) def __init__(self, *args, **kwargs): super(User, self).__init__(*args, **kwargs) self._meta.get_field("username").validators = [CallUsernameValidator()] class Band(models.Model): name = models.CharField(max_length=10) contest = models.ForeignKey(Contest) def __str__(self): return self.name class Frequency(models.Model): # qrg # band channel = models.CharField(max_length=3) qrg = models.DecimalField(max_digits=7, decimal_places=3) band = models.ForeignKey(Band) note = models.CharField(max_length=50, blank=True) def __str__(self): return "Channel %s: %s MHz" % (self.channel, self.qrg) class QSO(models.Model): reportValidator = RegexValidator("[1-5][1-9]") class Meta: index_together = [ ["owner", "call"], ] owner = models.ForeignKey(User, db_index=True) time = models.DateTimeField(blank=True) call = models.CharField(max_length=20, db_index=True) band = models.ForeignKey(Band) reportTX = models.CharField(max_length=7, default=59, verbose_name='RST-S', validators=[reportValidator]) reportRX = models.CharField(max_length=7, default=59, verbose_name='RST-R', validators=[reportValidator]) ownNo = models.IntegerField(verbose_name='Nr-S') otherNo = models.IntegerField(verbose_name='Nr-R') refStr = models.CharField(max_length=20, verbose_name="EXC") ref = models.ForeignKey(Reference, models.SET_NULL, null=True, blank=True) remarks = models.CharField(max_length=50, blank=True) def __str__(self): return "QSO no %s at %s with %s@%s %s/%s" % (self.ownNo, self.time.strftime("%H:%M"), self.call, self.refStr, self.reportTX, self.reportRX)