from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import AbstractUser 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", null=True, blank=True) def __str__(self): return self.name class Reference(models.Model): name = models.CharField(max_length=20, unique=True) description = models.TextField() def __str__(self): return self.name class User(AbstractUser): ref = models.ForeignKey(Reference, 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): owner = models.ForeignKey(User) time = models.DateTimeField(blank=True) call = models.CharField(max_length=20) band = models.ForeignKey(Band) reportTX = models.CharField(max_length=7, default=59) reportRX = models.CharField(max_length=7, default=59) ownNo = models.IntegerField() otherNo = models.IntegerField() refStr = models.CharField(max_length=20) ref = models.ForeignKey(Reference, null=True, blank=True) remarks = models.CharField(max_length=50, blank=True)