mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 07:51:09 -05:00
Refactor parks and rides views for improved organization and readability
- Updated imports in parks/views.py to use ParkReview as Review for clarity. - Enhanced road trip views in parks/views_roadtrip.py by removing unnecessary parameters and improving context handling. - Streamlined error handling and response messages in CreateTripView and FindParksAlongRouteView. - Improved code formatting and consistency across various methods in parks/views_roadtrip.py. - Refactored rides/models.py to import Company from models for better clarity. - Updated rides/views.py to import RideSearchForm from services for better organization. - Added a comprehensive Django best practices analysis document to memory-bank/documentation.
This commit is contained in:
@@ -4,7 +4,7 @@ from django.contrib.contenttypes.fields import GenericRelation
|
||||
from core.history import TrackedModel, DiffMixin
|
||||
from .events import get_ride_display_changes, get_ride_model_display_changes
|
||||
import pghistory
|
||||
from .company import Company
|
||||
from .models import Company
|
||||
|
||||
# Shared choices that will be used by multiple models
|
||||
CATEGORY_CHOICES = [
|
||||
@@ -17,13 +17,14 @@ CATEGORY_CHOICES = [
|
||||
('OT', 'Other'),
|
||||
]
|
||||
|
||||
|
||||
class RideEvent(models.Model, DiffMixin):
|
||||
"""Event model for tracking Ride changes - uses existing pghistory table"""
|
||||
|
||||
|
||||
pgh_id = models.AutoField(primary_key=True)
|
||||
pgh_created_at = models.DateTimeField(auto_now_add=True)
|
||||
pgh_label = models.TextField()
|
||||
|
||||
|
||||
# Original model fields
|
||||
id = models.BigIntegerField()
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -39,15 +40,16 @@ class RideEvent(models.Model, DiffMixin):
|
||||
max_height_in = models.PositiveIntegerField(null=True)
|
||||
capacity_per_hour = models.PositiveIntegerField(null=True)
|
||||
ride_duration_seconds = models.PositiveIntegerField(null=True)
|
||||
average_rating = models.DecimalField(max_digits=3, decimal_places=2, null=True)
|
||||
average_rating = models.DecimalField(
|
||||
max_digits=3, decimal_places=2, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
updated_at = models.DateTimeField()
|
||||
|
||||
|
||||
# Foreign keys as IDs
|
||||
park_id = models.BigIntegerField()
|
||||
park_area_id = models.BigIntegerField(null=True)
|
||||
ride_model_id = models.BigIntegerField(null=True)
|
||||
|
||||
|
||||
# Context fields
|
||||
pgh_obj = models.ForeignKey('Ride', on_delete=models.CASCADE)
|
||||
pgh_context = models.ForeignKey(
|
||||
@@ -66,13 +68,14 @@ class RideEvent(models.Model, DiffMixin):
|
||||
"""Returns human-readable changes"""
|
||||
return get_ride_display_changes(self.diff_against_previous())
|
||||
|
||||
|
||||
class RideModelEvent(models.Model, DiffMixin):
|
||||
"""Event model for tracking RideModel changes - uses existing pghistory table"""
|
||||
|
||||
|
||||
pgh_id = models.AutoField(primary_key=True)
|
||||
pgh_created_at = models.DateTimeField(auto_now_add=True)
|
||||
pgh_label = models.TextField()
|
||||
|
||||
|
||||
# Original model fields
|
||||
id = models.BigIntegerField()
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -80,10 +83,10 @@ class RideModelEvent(models.Model, DiffMixin):
|
||||
category = models.CharField(max_length=2)
|
||||
created_at = models.DateTimeField()
|
||||
updated_at = models.DateTimeField()
|
||||
|
||||
|
||||
# Foreign keys as IDs
|
||||
manufacturer_id = models.BigIntegerField(null=True)
|
||||
|
||||
|
||||
# Context fields
|
||||
pgh_obj = models.ForeignKey('RideModel', on_delete=models.CASCADE)
|
||||
pgh_context = models.ForeignKey(
|
||||
@@ -102,6 +105,7 @@ class RideModelEvent(models.Model, DiffMixin):
|
||||
"""Returns human-readable changes"""
|
||||
return get_ride_model_display_changes(self.diff_against_previous())
|
||||
|
||||
|
||||
class RideModel(TrackedModel):
|
||||
"""
|
||||
Represents a specific model/type of ride that can be manufactured by different companies.
|
||||
@@ -114,7 +118,8 @@ class RideModel(TrackedModel):
|
||||
related_name='ride_models',
|
||||
null=True,
|
||||
blank=True,
|
||||
limit_choices_to={'roles__contains': [Company.CompanyRole.MANUFACTURER]}
|
||||
limit_choices_to={'roles__contains': [
|
||||
Company.CompanyRole.MANUFACTURER]}
|
||||
)
|
||||
description = models.TextField(blank=True)
|
||||
category = models.CharField(
|
||||
@@ -131,6 +136,7 @@ class RideModel(TrackedModel):
|
||||
def __str__(self) -> str:
|
||||
return self.name if not self.manufacturer else f"{self.manufacturer.name} {self.name}"
|
||||
|
||||
|
||||
class Ride(TrackedModel):
|
||||
"""Model for individual ride installations at parks"""
|
||||
STATUS_CHOICES = [
|
||||
@@ -177,7 +183,8 @@ class Ride(TrackedModel):
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='manufactured_rides',
|
||||
limit_choices_to={'roles__contains': [Company.CompanyRole.MANUFACTURER]}
|
||||
limit_choices_to={'roles__contains': [
|
||||
Company.CompanyRole.MANUFACTURER]}
|
||||
)
|
||||
designer = models.ForeignKey(
|
||||
Company,
|
||||
@@ -234,6 +241,7 @@ class Ride(TrackedModel):
|
||||
self.slug = slugify(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class RollerCoasterStats(models.Model):
|
||||
"""Model for tracking roller coaster specific statistics"""
|
||||
TRACK_MATERIAL_CHOICES = [
|
||||
|
||||
Reference in New Issue
Block a user