define model on all Village views, remove Villages custom manager
This commit is contained in:
parent
4c60415336
commit
9bfc206b53
|
@ -1,9 +0,0 @@
|
|||
from django.db.models import QuerySet
|
||||
|
||||
|
||||
class VillageQuerySet(QuerySet):
|
||||
|
||||
def not_deleted(self):
|
||||
return self.filter(
|
||||
deleted=False
|
||||
)
|
|
@ -2,7 +2,6 @@ from django.urls import reverse_lazy
|
|||
from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from utils.models import UUIDModel, CampRelatedModel
|
||||
from .managers import VillageQuerySet
|
||||
|
||||
|
||||
class Village(UUIDModel, CampRelatedModel):
|
||||
|
@ -28,8 +27,6 @@ class Village(UUIDModel, CampRelatedModel):
|
|||
default=False,
|
||||
)
|
||||
|
||||
objects = VillageQuerySet.as_manager()
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s)" % (self.name, self.camp.title)
|
||||
|
||||
|
|
|
@ -11,16 +11,21 @@ from .mixins import EnsureWritableCampMixin
|
|||
|
||||
|
||||
class VillageListView(CampViewMixin, ListView):
|
||||
queryset = Village.objects.not_deleted()
|
||||
model = Village
|
||||
template_name = 'village_list.html'
|
||||
context_object_name = 'villages'
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(deleted=False)
|
||||
|
||||
class VillageDetailView(CampViewMixin, DetailView):
|
||||
queryset = Village.objects.not_deleted()
|
||||
model = Village
|
||||
template_name = 'village_detail.html'
|
||||
context_object_name = 'village'
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(deleted=False)
|
||||
|
||||
|
||||
class VillageCreateView(CampViewMixin, LoginRequiredMixin, EnsureWritableCampMixin, CreateView):
|
||||
model = Village
|
||||
|
@ -56,7 +61,6 @@ class EnsureUserOwnsVillageMixin(SingleObjectMixin):
|
|||
|
||||
class VillageUpdateView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequiredMixin, EnsureWritableCampMixin, UpdateView):
|
||||
model = Village
|
||||
queryset = Village.objects.not_deleted()
|
||||
template_name = 'village_form.html'
|
||||
fields = ['name', 'description', 'private']
|
||||
|
||||
|
@ -69,6 +73,9 @@ class VillageUpdateView(CampViewMixin, EnsureUserOwnsVillageMixin, LoginRequired
|
|||
def get_success_url(self):
|
||||
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):
|
||||
model = Village
|
||||
|
|
Loading…
Reference in a new issue