add category views for each type of ride, add ride designers

This commit is contained in:
pacnpal
2024-11-04 00:33:19 +00:00
parent 07526dcba8
commit ae913e757a
35 changed files with 1607 additions and 275 deletions

29
designers/views.py Normal file
View File

@@ -0,0 +1,29 @@
from django.views.generic import DetailView
from .models import Designer
from django.db.models import Count
class DesignerDetailView(DetailView):
model = Designer
template_name = 'designers/designer_detail.html'
context_object_name = 'designer'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Get all rides by this designer
context['rides'] = self.object.rides.select_related(
'park',
'manufacturer',
'coaster_stats'
).order_by('-opening_date')
# Get stats
context['stats'] = {
'total_rides': self.object.rides.count(),
'total_parks': self.object.rides.values('park').distinct().count(),
'total_coasters': self.object.rides.filter(category='RC').count(),
'total_countries': self.object.rides.values(
'park__location__country'
).distinct().count(),
}
return context