mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:51:09 -05:00
- Implemented OperatorListView and OperatorDetailView for managing operators. - Created corresponding templates for operator listing and detail views. - Added PropertyOwnerListView and PropertyOwnerDetailView for managing property owners. - Developed templates for property owner listing and detail views. - Established relationships between parks and operators, and parks and property owners in the models. - Created migrations to reflect the new relationships and fields in the database. - Added admin interfaces for PropertyOwner management. - Implemented tests for operators and property owners.
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from django.views.generic import ListView, DetailView
|
|
from django.db.models import QuerySet
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from core.views import SlugRedirectMixin
|
|
from .models import Operator
|
|
from typing import Optional, Any, Dict
|
|
|
|
|
|
class OperatorListView(ListView):
|
|
model = Operator
|
|
template_name = "operators/operator_list.html"
|
|
context_object_name = "operators"
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self) -> QuerySet[Operator]:
|
|
return Operator.objects.all().order_by('name')
|
|
|
|
|
|
class OperatorDetailView(SlugRedirectMixin, DetailView):
|
|
model = Operator
|
|
template_name = "operators/operator_detail.html"
|
|
context_object_name = "operator"
|
|
|
|
def get_object(self, queryset: Optional[QuerySet[Operator]] = None) -> Operator:
|
|
if queryset is None:
|
|
queryset = self.get_queryset()
|
|
slug = self.kwargs.get(self.slug_url_kwarg)
|
|
if slug is None:
|
|
raise ObjectDoesNotExist("No slug provided")
|
|
operator, _ = Operator.get_by_slug(slug)
|
|
return operator
|
|
|
|
def get_queryset(self) -> QuerySet[Operator]:
|
|
return Operator.objects.all()
|
|
|
|
def get_context_data(self, **kwargs) -> Dict[str, Any]:
|
|
context = super().get_context_data(**kwargs)
|
|
operator = self.get_object()
|
|
|
|
# Add related parks to context (using related_name="parks" from Park model)
|
|
context['parks'] = operator.parks.all().order_by('name')
|
|
|
|
return context
|