Make camp and slug unique together on villages. Also fix some url errors.
This commit is contained in:
parent
b151192d02
commit
62381a50e6
20
src/villages/migrations/0010_auto_20170318_1506.py
Normal file
20
src/villages/migrations/0010_auto_20170318_1506.py
Normal file
|
@ -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')]),
|
||||
),
|
||||
]
|
|
@ -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')
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<button type="submit" class="btn btn-danger form-control">Confirm</button>
|
||||
<br />
|
||||
<br />
|
||||
<a href="{% url 'village_detail' slug=village.slug %}" class="btn btn-default form-control">Cancel</a>
|
||||
<a href="{% url 'village_detail' camp_slug=village.camp.slug slug=village.slug %}"
|
||||
class="btn btn-default form-control">Cancel</a>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
Loading…
Reference in a new issue