define model on all Village views, remove Villages custom manager

This commit is contained in:
Thomas Steen Rasmussen 2018-06-21 12:32:02 +02:00
parent 4c60415336
commit 9bfc206b53
3 changed files with 10 additions and 15 deletions

View file

@ -1,9 +0,0 @@
from django.db.models import QuerySet
class VillageQuerySet(QuerySet):
def not_deleted(self):
return self.filter(
deleted=False
)

View file

@ -2,7 +2,6 @@ from django.urls import reverse_lazy
from django.db import models from django.db import models
from django.utils.text import slugify from django.utils.text import slugify
from utils.models import UUIDModel, CampRelatedModel from utils.models import UUIDModel, CampRelatedModel
from .managers import VillageQuerySet
class Village(UUIDModel, CampRelatedModel): class Village(UUIDModel, CampRelatedModel):
@ -28,8 +27,6 @@ class Village(UUIDModel, CampRelatedModel):
default=False, default=False,
) )
objects = VillageQuerySet.as_manager()
def __str__(self): def __str__(self):
return "%s (%s)" % (self.name, self.camp.title) return "%s (%s)" % (self.name, self.camp.title)

View file

@ -11,16 +11,21 @@ from .mixins import EnsureWritableCampMixin
class VillageListView(CampViewMixin, ListView): class VillageListView(CampViewMixin, ListView):
queryset = Village.objects.not_deleted() model = Village
template_name = 'village_list.html' template_name = 'village_list.html'
context_object_name = 'villages' context_object_name = 'villages'
def get_queryset(self):
return super().get_queryset().filter(deleted=False)
class VillageDetailView(CampViewMixin, DetailView): class VillageDetailView(CampViewMixin, DetailView):
queryset = Village.objects.not_deleted() model = Village
template_name = 'village_detail.html' template_name = 'village_detail.html'
context_object_name = 'village' context_object_name = 'village'
def get_queryset(self):
return super().get_queryset().filter(deleted=False)
class VillageCreateView(CampViewMixin, LoginRequiredMixin, EnsureWritableCampMixin, CreateView): class VillageCreateView(CampViewMixin, LoginRequiredMixin, EnsureWritableCampMixin, CreateView):
model = Village model = Village
@ -56,7 +61,6 @@ class EnsureUserOwnsVillageMixin(SingleObjectMixin):
class VillageUpdateView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequiredMixin, EnsureWritableCampMixin, UpdateView): class VillageUpdateView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequiredMixin, EnsureWritableCampMixin, UpdateView):
model = Village model = Village
queryset = Village.objects.not_deleted()
template_name = 'village_form.html' template_name = 'village_form.html'
fields = ['name', 'description', 'private'] fields = ['name', 'description', 'private']
@ -69,6 +73,9 @@ class VillageUpdateView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequired
def get_success_url(self): def get_success_url(self):
return self.get_object().get_absolute_url() return self.get_object().get_absolute_url()
def get_queryset(self):
return super().get_queryset().filter(deleted=False)
class VillageDeleteView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequiredMixin, EnsureWritableCampMixin, DeleteView): class VillageDeleteView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequiredMixin, EnsureWritableCampMixin, DeleteView):
model = Village model = Village