Db idx and on_delete for foreignkeys
This commit is contained in:
parent
8d58030cc0
commit
110271457d
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-01-23 01:39
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contest', '0008_auto_20170119_1202'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='contest',
|
||||
name='callQrg',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='contest.Frequency'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='frequency',
|
||||
name='note',
|
||||
field=models.CharField(blank=True, max_length=50),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='call',
|
||||
field=models.CharField(db_index=True, max_length=20),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='otherNo',
|
||||
field=models.IntegerField(verbose_name='Nr-R'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='ownNo',
|
||||
field=models.IntegerField(verbose_name='Nr-S'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='ref',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='contest.Reference'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='refStr',
|
||||
field=models.CharField(max_length=20, verbose_name='EXC'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='reportRX',
|
||||
field=models.CharField(default=59, max_length=7, validators=[django.core.validators.RegexValidator('[1-5][1-9]')], verbose_name='RST-R'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qso',
|
||||
name='reportTX',
|
||||
field=models.CharField(default=59, max_length=7, validators=[django.core.validators.RegexValidator('[1-5][1-9]')], verbose_name='RST-S'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='reference',
|
||||
name='name',
|
||||
field=models.CharField(db_index=True, max_length=20, unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='ref',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='contest.Reference'),
|
||||
),
|
||||
migrations.AlterIndexTogether(
|
||||
name='qso',
|
||||
index_together=set([('owner', 'call')]),
|
||||
),
|
||||
]
|
|
@ -9,20 +9,20 @@ 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)
|
||||
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)
|
||||
name = models.CharField(max_length=20, unique=True, db_index=True)
|
||||
description = models.TextField()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class User(AbstractUser):
|
||||
ref = models.ForeignKey(Reference, null=True, blank=True)
|
||||
ref = models.ForeignKey(Reference, models.SET_NULL,null=True, blank=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(User, self).__init__(*args, **kwargs)
|
||||
|
@ -50,13 +50,16 @@ class Frequency(models.Model):
|
|||
class QSO(models.Model):
|
||||
reportValidator = RegexValidator("[1-5][1-9]")
|
||||
|
||||
owner = models.ForeignKey(User)
|
||||
class Meta:
|
||||
index_together = [
|
||||
["owner", "call"],
|
||||
]
|
||||
|
||||
owner = models.ForeignKey(User, db_index=True)
|
||||
time = models.DateTimeField(blank=True)
|
||||
call = models.CharField(max_length=20)
|
||||
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])
|
||||
|
||||
|
@ -64,7 +67,7 @@ class QSO(models.Model):
|
|||
otherNo = models.IntegerField(verbose_name='Nr-R')
|
||||
|
||||
refStr = models.CharField(max_length=20, verbose_name="EXC")
|
||||
ref = models.ForeignKey(Reference, null=True, blank=True)
|
||||
ref = models.ForeignKey(Reference, models.SET_NULL, null=True, blank=True)
|
||||
|
||||
remarks = models.CharField(max_length=50, blank=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue