mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 11:51:10 -05:00
fixing the home page
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -47,8 +47,8 @@ class Park(HistoricalModel):
|
||||
average_rating = models.DecimalField(
|
||||
max_digits=3, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
total_rides = models.IntegerField(null=True, blank=True)
|
||||
total_roller_coasters = models.IntegerField(null=True, blank=True)
|
||||
ride_count = models.IntegerField(null=True, blank=True)
|
||||
coaster_count = models.IntegerField(null=True, blank=True)
|
||||
|
||||
# Relationships
|
||||
owner = models.ForeignKey(
|
||||
|
||||
@@ -6,22 +6,22 @@ from rides.models import Ride
|
||||
from .models import Park
|
||||
|
||||
def update_park_ride_counts(park):
|
||||
"""Update total_rides and total_roller_coasters for a park"""
|
||||
"""Update ride_count and coaster_count for a park"""
|
||||
operating_rides = Q(status='OPERATING')
|
||||
|
||||
# Count total operating rides
|
||||
total_rides = park.rides.filter(operating_rides).count()
|
||||
ride_count = park.rides.filter(operating_rides).count()
|
||||
|
||||
# Count total operating roller coasters
|
||||
total_coasters = park.rides.filter(
|
||||
coaster_count = park.rides.filter(
|
||||
operating_rides,
|
||||
category='RC'
|
||||
).count()
|
||||
|
||||
# Update park counts
|
||||
Park.objects.filter(id=park.id).update(
|
||||
total_rides=total_rides,
|
||||
total_roller_coasters=total_coasters
|
||||
ride_count=ride_count,
|
||||
coaster_count=coaster_count
|
||||
)
|
||||
|
||||
@receiver(post_save, sender=Ride)
|
||||
|
||||
@@ -3,7 +3,7 @@ from django.views.generic import DetailView, ListView, CreateView, UpdateView
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.urls import reverse
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Avg, Count
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib import messages
|
||||
@@ -18,6 +18,7 @@ from moderation.models import EditSubmission
|
||||
from media.models import Photo
|
||||
from location.models import Location
|
||||
from reviews.models import Review # Import the Review model
|
||||
from analytics.models import PageView # Import PageView for tracking views
|
||||
|
||||
|
||||
def location_search(request):
|
||||
@@ -131,6 +132,13 @@ class ParkListView(ListView):
|
||||
if statuses:
|
||||
queryset = queryset.filter(status__in=statuses)
|
||||
|
||||
# Annotate with ride count, coaster count, and average review rating
|
||||
queryset = queryset.annotate(
|
||||
ride_count=Count('rides'),
|
||||
coaster_count=Count('rides', filter=Q(rides__type='coaster')),
|
||||
average_rating=Avg('reviews__rating')
|
||||
)
|
||||
|
||||
return queryset.distinct()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user