add some unique constraints here and there to ensure data integrity

This commit is contained in:
Thomas Steen Rasmussen 2017-01-28 18:43:55 +01:00
parent f6e18a6dbb
commit 9f082e63ec
4 changed files with 70 additions and 1 deletions

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-28 17:41
from __future__ import unicode_literals
import django.contrib.postgres.fields.ranges
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('camps', '0017_remove_camp_description'),
]
operations = [
migrations.AlterField(
model_name='camp',
name='buildup',
field=django.contrib.postgres.fields.ranges.DateTimeRangeField(help_text=b'The camp buildup period.', verbose_name=b'Buildup Period'),
),
migrations.AlterField(
model_name='camp',
name='camp',
field=django.contrib.postgres.fields.ranges.DateTimeRangeField(help_text=b'The camp period.', verbose_name=b'Camp Period'),
),
migrations.AlterField(
model_name='camp',
name='teardown',
field=django.contrib.postgres.fields.ranges.DateTimeRangeField(help_text=b'The camp teardown period.', verbose_name=b'Teardown period'),
),
]

View file

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-28 17:41
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('camps', '0018_auto_20170128_1841'),
('program', '0014_speaker_camp'),
]
operations = [
migrations.AlterField(
model_name='eventtype',
name='name',
field=models.CharField(max_length=100, unique=True),
),
migrations.AlterField(
model_name='speaker',
name='events',
field=models.ManyToManyField(blank=True, to='program.Event'),
),
migrations.AlterUniqueTogether(
name='event',
unique_together=set([('camp', 'title'), ('camp', 'slug')]),
),
migrations.AlterUniqueTogether(
name='speaker',
unique_together=set([('camp', 'name'), ('camp', 'slug')]),
),
]

View file

@ -10,7 +10,7 @@ from datetime import timedelta
class EventType(CreatedUpdatedModel):
""" Every event needs to have a type. """
name = models.CharField(max_length=100)
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField()
color = models.CharField(max_length=50)
light_text = models.BooleanField(default=False)
@ -29,6 +29,7 @@ class Event(CreatedUpdatedModel):
class Meta:
ordering = ['title']
unique_together = (('camp', 'slug'), ('camp', 'title'))
def __unicode__(self):
return '%s (%s)' % (self.title, self.camp.title)
@ -104,6 +105,7 @@ class Speaker(CreatedUpdatedModel):
class Meta:
ordering = ['name']
unique_together = (('camp', 'name'), ('camp', 'slug'))
def __unicode__(self):
return '%s (%s)' % (self.name, self.camp)

View file

@ -103,6 +103,8 @@ class EventDetailView(CampViewMixin, DetailView):
model = models.Event
template_name = 'program_event_detail.html'
def get_object(self):
return self.camp.events.get(slug=self.kwargs['slug'])
class CallForSpeakersView(CampViewMixin, TemplateView):
def get_template_names(self):