mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:11:08 -05:00
add category views for each type of ride, add ride designers
This commit is contained in:
29
designers/views.py
Normal file
29
designers/views.py
Normal 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
|
||||
Reference in New Issue
Block a user