mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:51:10 -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 Manufacturer
|
|
from typing import Optional, Any, Dict
|
|
|
|
|
|
class ManufacturerListView(ListView):
|
|
model = Manufacturer
|
|
template_name = "manufacturers/manufacturer_list.html"
|
|
context_object_name = "manufacturers"
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self) -> QuerySet[Manufacturer]:
|
|
return Manufacturer.objects.all().order_by('name')
|
|
|
|
|
|
class ManufacturerDetailView(SlugRedirectMixin, DetailView):
|
|
model = Manufacturer
|
|
template_name = "manufacturers/manufacturer_detail.html"
|
|
context_object_name = "manufacturer"
|
|
|
|
def get_object(self, queryset: Optional[QuerySet[Manufacturer]] = None) -> Manufacturer:
|
|
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")
|
|
manufacturer, _ = Manufacturer.get_by_slug(slug)
|
|
return manufacturer
|
|
|
|
def get_queryset(self) -> QuerySet[Manufacturer]:
|
|
return Manufacturer.objects.all()
|
|
|
|
def get_context_data(self, **kwargs) -> Dict[str, Any]:
|
|
context = super().get_context_data(**kwargs)
|
|
manufacturer = self.get_object()
|
|
|
|
# Add related rides to context (using related_name="rides" from Ride model)
|
|
context['rides'] = manufacturer.rides.all().order_by('name')
|
|
|
|
return context
|