mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 01:47:04 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -30,23 +30,15 @@ class ParkQuerySet(StatusQuerySet, ReviewableQuerySet, LocationQuerySet):
|
||||
distinct=True,
|
||||
),
|
||||
area_count=Count("areas", distinct=True),
|
||||
review_count=Count(
|
||||
"reviews", filter=Q(reviews__is_published=True), distinct=True
|
||||
),
|
||||
average_rating_calculated=Avg(
|
||||
"reviews__rating", filter=Q(reviews__is_published=True)
|
||||
),
|
||||
review_count=Count("reviews", filter=Q(reviews__is_published=True), distinct=True),
|
||||
average_rating_calculated=Avg("reviews__rating", filter=Q(reviews__is_published=True)),
|
||||
latest_ride_opening=Max("rides__opening_date"),
|
||||
oldest_ride_opening=Min("rides__opening_date"),
|
||||
)
|
||||
|
||||
def optimized_for_list(self):
|
||||
"""Optimize for park list display."""
|
||||
return (
|
||||
self.select_related("operator", "property_owner")
|
||||
.prefetch_related("location")
|
||||
.with_complete_stats()
|
||||
)
|
||||
return self.select_related("operator", "property_owner").prefetch_related("location").with_complete_stats()
|
||||
|
||||
def optimized_for_detail(self):
|
||||
"""Optimize for park detail display."""
|
||||
@@ -59,9 +51,9 @@ class ParkQuerySet(StatusQuerySet, ReviewableQuerySet, LocationQuerySet):
|
||||
"areas",
|
||||
Prefetch(
|
||||
"rides",
|
||||
queryset=Ride.objects.select_related(
|
||||
"manufacturer", "designer", "ride_model", "park_area"
|
||||
).order_by("name"),
|
||||
queryset=Ride.objects.select_related("manufacturer", "designer", "ride_model", "park_area").order_by(
|
||||
"name"
|
||||
),
|
||||
),
|
||||
Prefetch(
|
||||
"reviews",
|
||||
@@ -82,9 +74,7 @@ class ParkQuerySet(StatusQuerySet, ReviewableQuerySet, LocationQuerySet):
|
||||
|
||||
def with_minimum_coasters(self, *, min_coasters: int = 5):
|
||||
"""Filter parks with minimum number of coasters."""
|
||||
return self.with_complete_stats().filter(
|
||||
coaster_count_calculated__gte=min_coasters
|
||||
)
|
||||
return self.with_complete_stats().filter(coaster_count_calculated__gte=min_coasters)
|
||||
|
||||
def large_parks(self, *, min_acres: float = 100.0):
|
||||
"""Filter for large parks."""
|
||||
@@ -123,16 +113,10 @@ class ParkQuerySet(StatusQuerySet, ReviewableQuerySet, LocationQuerySet):
|
||||
"""Optimized search for autocomplete."""
|
||||
return (
|
||||
self.filter(
|
||||
Q(name__icontains=query)
|
||||
| Q(location__city__icontains=query)
|
||||
| Q(location__state__icontains=query)
|
||||
Q(name__icontains=query) | Q(location__city__icontains=query) | Q(location__state__icontains=query)
|
||||
)
|
||||
.select_related("operator", "location")
|
||||
.only(
|
||||
"id", "name", "slug",
|
||||
"location__city", "location__state",
|
||||
"operator__name"
|
||||
)[:limit]
|
||||
.only("id", "name", "slug", "location__city", "location__state", "operator__name")[:limit]
|
||||
)
|
||||
|
||||
def with_location(self):
|
||||
@@ -247,9 +231,7 @@ class ParkReviewManager(BaseManager):
|
||||
return self.get_queryset().for_park(park_id=park_id)
|
||||
|
||||
def by_rating_range(self, *, min_rating: int = 1, max_rating: int = 10):
|
||||
return self.get_queryset().by_rating_range(
|
||||
min_rating=min_rating, max_rating=max_rating
|
||||
)
|
||||
return self.get_queryset().by_rating_range(min_rating=min_rating, max_rating=max_rating)
|
||||
|
||||
def moderation_required(self):
|
||||
return self.get_queryset().moderation_required()
|
||||
@@ -275,17 +257,12 @@ class CompanyQuerySet(BaseQuerySet):
|
||||
return self.annotate(
|
||||
operated_parks_count=Count("operated_parks", distinct=True),
|
||||
owned_parks_count=Count("owned_parks", distinct=True),
|
||||
total_parks_involvement=Count("operated_parks", distinct=True)
|
||||
+ Count("owned_parks", distinct=True),
|
||||
total_parks_involvement=Count("operated_parks", distinct=True) + Count("owned_parks", distinct=True),
|
||||
)
|
||||
|
||||
def major_operators(self, *, min_parks: int = 5):
|
||||
"""Filter for major park operators."""
|
||||
return (
|
||||
self.operators()
|
||||
.with_park_counts()
|
||||
.filter(operated_parks_count__gte=min_parks)
|
||||
)
|
||||
return self.operators().with_park_counts().filter(operated_parks_count__gte=min_parks)
|
||||
|
||||
def optimized_for_list(self):
|
||||
"""Optimize for company list display."""
|
||||
@@ -313,7 +290,7 @@ class CompanyManager(BaseManager):
|
||||
self.get_queryset()
|
||||
.manufacturers()
|
||||
.annotate(ride_count=Count("manufactured_rides", distinct=True))
|
||||
.only('id', 'name', 'slug', 'roles', 'description')
|
||||
.only("id", "name", "slug", "roles", "description")
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
@@ -323,7 +300,7 @@ class CompanyManager(BaseManager):
|
||||
self.get_queryset()
|
||||
.filter(roles__contains=["DESIGNER"])
|
||||
.annotate(ride_count=Count("designed_rides", distinct=True))
|
||||
.only('id', 'name', 'slug', 'roles', 'description')
|
||||
.only("id", "name", "slug", "roles", "description")
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
@@ -333,6 +310,6 @@ class CompanyManager(BaseManager):
|
||||
self.get_queryset()
|
||||
.operators()
|
||||
.with_park_counts()
|
||||
.only('id', 'name', 'slug', 'roles', 'description')
|
||||
.only("id", "name", "slug", "roles", "description")
|
||||
.order_by("name")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user