cqtu/contest/models.py

65 lines
1.8 KiB
Python
Raw Normal View History

2017-01-18 02:25:12 +01:00
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import AbstractUser
2017-01-19 18:42:11 +01:00
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)
2017-01-19 18:42:11 +01:00
def __str__(self):
return self.name
2017-01-18 02:25:12 +01:00
class Reference(models.Model):
name = models.CharField(max_length=20, unique=True)
description = models.TextField()
2017-01-19 18:42:11 +01:00
def __str__(self):
return self.name
2017-01-18 02:25:12 +01:00
class User(AbstractUser):
ref = models.ForeignKey(Reference, null=True, blank=True)
2017-01-19 18:42:11 +01:00
def __init__(self, *args, **kwargs):
super(User, self).__init__(*args, **kwargs)
self._meta.get_field("username").validators = [CallUsernameValidator()]
2017-01-18 02:25:12 +01:00
class Band(models.Model):
name = models.CharField(max_length=10)
2017-01-19 18:42:11 +01:00
contest = models.ForeignKey(Contest)
2017-01-18 02:25:12 +01:00
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)
2017-01-19 18:42:11 +01:00
2017-01-18 02:25:12 +01:00
def __str__(self):
return "Channel %s: %s MHz" % (self.channel, self.qrg)
2017-01-19 18:42:11 +01:00
class QSO(models.Model):
owner = models.ForeignKey(User)
time = models.DateTimeField(blank=True)
call = models.CharField(max_length=20)
band = models.ForeignKey(Band)
2017-01-21 00:16:39 +01:00
reportTX = models.CharField(max_length=7, default=59, verbose_name='RST-S')
reportRX = models.CharField(max_length=7, default=59, verbose_name='RST-R')
2017-01-19 18:42:11 +01:00
2017-01-21 00:16:39 +01:00
ownNo = models.IntegerField(verbose_name='Nr-S')
otherNo = models.IntegerField(verbose_name='Nr-R')
2017-01-19 18:42:11 +01:00
2017-01-21 00:16:39 +01:00
refStr = models.CharField(max_length=20, verbose_name="Exc")
2017-01-19 18:42:11 +01:00
ref = models.ForeignKey(Reference, null=True, blank=True)
remarks = models.CharField(max_length=50, blank=True)