mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 11:11:10 -05:00
feat: Refactor rides app with unique constraints, mixins, and enhanced documentation
- Added migration to convert unique_together constraints to UniqueConstraint for RideModel. - Introduced RideFormMixin for handling entity suggestions in ride forms. - Created comprehensive code standards documentation outlining formatting, docstring requirements, complexity guidelines, and testing requirements. - Established error handling guidelines with a structured exception hierarchy and best practices for API and view error handling. - Documented view pattern guidelines, emphasizing the use of CBVs, FBVs, and ViewSets with examples. - Implemented a benchmarking script for query performance analysis and optimization. - Developed security documentation detailing measures, configurations, and a security checklist. - Compiled a database optimization guide covering indexing strategies, query optimization patterns, and computed fields.
This commit is contained in:
@@ -75,13 +75,14 @@ class RideQuerySet(StatusQuerySet, ReviewableQuerySet):
|
||||
|
||||
return self.select_related(
|
||||
"park",
|
||||
"park__location",
|
||||
"park_area",
|
||||
"manufacturer",
|
||||
"designer",
|
||||
"ride_model",
|
||||
"ride_model__manufacturer",
|
||||
).prefetch_related(
|
||||
"location",
|
||||
"rollercoaster_stats",
|
||||
"coaster_stats",
|
||||
Prefetch(
|
||||
"reviews",
|
||||
queryset=RideReview.objects.select_related("user")
|
||||
@@ -91,6 +92,12 @@ class RideQuerySet(StatusQuerySet, ReviewableQuerySet):
|
||||
"photos",
|
||||
)
|
||||
|
||||
def with_coaster_stats(self):
|
||||
"""Always prefetch coaster_stats for roller coaster queries."""
|
||||
return self.select_related(
|
||||
"park", "manufacturer", "ride_model"
|
||||
).prefetch_related("coaster_stats")
|
||||
|
||||
def for_map_display(self):
|
||||
"""Optimize for map display."""
|
||||
return (
|
||||
@@ -176,6 +183,10 @@ class RideManager(StatusManager, ReviewableManager):
|
||||
def optimized_for_detail(self):
|
||||
return self.get_queryset().optimized_for_detail()
|
||||
|
||||
def with_coaster_stats(self):
|
||||
"""Always prefetch coaster_stats for roller coaster queries."""
|
||||
return self.get_queryset().with_coaster_stats()
|
||||
|
||||
|
||||
class RideModelQuerySet(BaseQuerySet):
|
||||
"""QuerySet for RideModel model."""
|
||||
|
||||
Reference in New Issue
Block a user