diff --git a/src/villages/migrations/0010_auto_20170318_1506.py b/src/villages/migrations/0010_auto_20170318_1506.py new file mode 100644 index 00000000..c4b1c4a5 --- /dev/null +++ b/src/villages/migrations/0010_auto_20170318_1506.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-03-18 14:06 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('camps', '0020_camp_read_only'), + ('villages', '0009_auto_20161229_2143'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='village', + unique_together=set([('slug', 'camp')]), + ), + ] diff --git a/src/villages/models.py b/src/villages/models.py index dbd1856e..95bced02 100644 --- a/src/villages/models.py +++ b/src/villages/models.py @@ -9,6 +9,7 @@ class Village(UUIDModel, CampRelatedModel): class Meta: ordering = ['name'] + unique_together = ('slug', 'camp') contact = models.ForeignKey('auth.User') camp = models.ForeignKey('camps.Camp') diff --git a/src/villages/templates/village_confirm_delete.html b/src/villages/templates/village_confirm_delete.html index f3a8207a..a06ca8e3 100644 --- a/src/villages/templates/village_confirm_delete.html +++ b/src/villages/templates/village_confirm_delete.html @@ -8,6 +8,7 @@

- Cancel + Cancel {% endblock %} diff --git a/src/villages/views.py b/src/villages/views.py index 69fa59a9..bad5bfdb 100644 --- a/src/villages/views.py +++ b/src/villages/views.py @@ -25,7 +25,6 @@ class VillageCreateView(LoginRequiredMixin, CreateView): model = Village template_name = 'village_form.html' fields = ['name', 'description', 'private'] - success_url = reverse_lazy('villages:list') def form_valid(self, form): village = form.save(commit=False) @@ -34,6 +33,9 @@ class VillageCreateView(LoginRequiredMixin, CreateView): village.save() return HttpResponseRedirect(village.get_absolute_url()) + def get_success_url(self): + return reverse_lazy('village_list', kwargs={"camp_slug": self.object.camp.slug}) + class EnsureUserOwnsVillageMixin(SingleObjectMixin): model = Village @@ -61,7 +63,9 @@ class VillageUpdateView(EnsureUserOwnsVillageMixin, LoginRequiredMixin, UpdateVi class VillageDeleteView(EnsureUserOwnsVillageMixin, LoginRequiredMixin, DeleteView): model = Village - success_url = reverse_lazy('villages:list') template_name = 'village_confirm_delete.html' context_object_name = 'village' + def get_success_url(self): + return reverse_lazy('village_list', kwargs={"camp_slug": self.object.camp.slug}) +