From 9f082e63ec9a3a953dbf2452ebb78ea5ded2b559 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sat, 28 Jan 2017 18:43:55 +0100 Subject: [PATCH] add some unique constraints here and there to ensure data integrity --- camps/migrations/0018_auto_20170128_1841.py | 31 +++++++++++++++++ program/migrations/0015_auto_20170128_1841.py | 34 +++++++++++++++++++ program/models.py | 4 ++- program/views.py | 2 ++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 camps/migrations/0018_auto_20170128_1841.py create mode 100644 program/migrations/0015_auto_20170128_1841.py diff --git a/camps/migrations/0018_auto_20170128_1841.py b/camps/migrations/0018_auto_20170128_1841.py new file mode 100644 index 00000000..160a4c7f --- /dev/null +++ b/camps/migrations/0018_auto_20170128_1841.py @@ -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'), + ), + ] diff --git a/program/migrations/0015_auto_20170128_1841.py b/program/migrations/0015_auto_20170128_1841.py new file mode 100644 index 00000000..37296489 --- /dev/null +++ b/program/migrations/0015_auto_20170128_1841.py @@ -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')]), + ), + ] diff --git a/program/models.py b/program/models.py index 2cb877e0..6bfc71f2 100644 --- a/program/models.py +++ b/program/models.py @@ -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) diff --git a/program/views.py b/program/views.py index beb937a7..217635a9 100644 --- a/program/views.py +++ b/program/views.py @@ -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):