mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:31:07 -05:00
feat(rides): populate slugs for existing RideModel records and ensure uniqueness
- Added migration 0011 to populate unique slugs for existing RideModel records based on manufacturer and model names. - Implemented logic to ensure slug uniqueness during population. - Added reverse migration to clear slugs if needed. feat(rides): enforce unique slugs for RideModel - Created migration 0012 to alter the slug field in RideModel to be unique. - Updated the slug field to include help text and a maximum length of 255 characters. docs: integrate Cloudflare Images into rides and parks models - Updated RidePhoto and ParkPhoto models to use CloudflareImagesField for image storage. - Enhanced API serializers for rides and parks to support Cloudflare Images, including new fields for image URLs and variants. - Provided comprehensive OpenAPI schema metadata for new fields. - Documented database migrations for the integration. - Detailed configuration settings for Cloudflare Images. - Updated API response formats to include Cloudflare Images URLs and variants. - Added examples for uploading photos via API and outlined testing procedures.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-28 18:17
|
||||
|
||||
import cloudflare_images.field
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0007_ridephoto_ridephotoevent_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="ridephoto",
|
||||
name="image",
|
||||
field=cloudflare_images.field.CloudflareImagesField(
|
||||
help_text="Ride photo stored on Cloudflare Images",
|
||||
upload_to="",
|
||||
variant="public",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="ridephotoevent",
|
||||
name="image",
|
||||
field=cloudflare_images.field.CloudflareImagesField(
|
||||
help_text="Ride photo stored on Cloudflare Images",
|
||||
upload_to="",
|
||||
variant="public",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,105 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-28 18:35
|
||||
|
||||
import django.db.models.deletion
|
||||
import pgtrigger.compiler
|
||||
import pgtrigger.migrations
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0008_cloudflare_images_integration"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
pgtrigger.migrations.RemoveTrigger(
|
||||
model_name="ride",
|
||||
name="insert_insert",
|
||||
),
|
||||
pgtrigger.migrations.RemoveTrigger(
|
||||
model_name="ride",
|
||||
name="update_update",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="ride",
|
||||
name="banner_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="Photo to use as banner image for this ride",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="rides_using_as_banner",
|
||||
to="rides.ridephoto",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="ride",
|
||||
name="card_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="Photo to use as card image for this ride",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="rides_using_as_card",
|
||||
to="rides.ridephoto",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="rideevent",
|
||||
name="banner_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
db_constraint=False,
|
||||
help_text="Photo to use as banner image for this ride",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name="+",
|
||||
related_query_name="+",
|
||||
to="rides.ridephoto",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="rideevent",
|
||||
name="card_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
db_constraint=False,
|
||||
help_text="Photo to use as card image for this ride",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name="+",
|
||||
related_query_name="+",
|
||||
to="rides.ridephoto",
|
||||
),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="ride",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="insert_insert",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
func='INSERT INTO "rides_rideevent" ("average_rating", "banner_image_id", "capacity_per_hour", "card_image_id", "category", "closing_date", "created_at", "description", "designer_id", "id", "manufacturer_id", "max_height_in", "min_height_in", "name", "opening_date", "park_area_id", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "post_closing_status", "ride_duration_seconds", "ride_model_id", "slug", "status", "status_since", "updated_at") VALUES (NEW."average_rating", NEW."banner_image_id", NEW."capacity_per_hour", NEW."card_image_id", NEW."category", NEW."closing_date", NEW."created_at", NEW."description", NEW."designer_id", NEW."id", NEW."manufacturer_id", NEW."max_height_in", NEW."min_height_in", NEW."name", NEW."opening_date", NEW."park_area_id", NEW."park_id", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."post_closing_status", NEW."ride_duration_seconds", NEW."ride_model_id", NEW."slug", NEW."status", NEW."status_since", NEW."updated_at"); RETURN NULL;',
|
||||
hash="462120d462bacf795e3e8d2d48e56a8adb85c63b",
|
||||
operation="INSERT",
|
||||
pgid="pgtrigger_insert_insert_52074",
|
||||
table="rides_ride",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="ride",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="update_update",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
|
||||
func='INSERT INTO "rides_rideevent" ("average_rating", "banner_image_id", "capacity_per_hour", "card_image_id", "category", "closing_date", "created_at", "description", "designer_id", "id", "manufacturer_id", "max_height_in", "min_height_in", "name", "opening_date", "park_area_id", "park_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "post_closing_status", "ride_duration_seconds", "ride_model_id", "slug", "status", "status_since", "updated_at") VALUES (NEW."average_rating", NEW."banner_image_id", NEW."capacity_per_hour", NEW."card_image_id", NEW."category", NEW."closing_date", NEW."created_at", NEW."description", NEW."designer_id", NEW."id", NEW."manufacturer_id", NEW."max_height_in", NEW."min_height_in", NEW."name", NEW."opening_date", NEW."park_area_id", NEW."park_id", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."post_closing_status", NEW."ride_duration_seconds", NEW."ride_model_id", NEW."slug", NEW."status", NEW."status_since", NEW."updated_at"); RETURN NULL;',
|
||||
hash="dc36bcf1b24242b781d63799024095b0f8da79b6",
|
||||
operation="UPDATE",
|
||||
pgid="pgtrigger_update_update_4917a",
|
||||
table="rides_ride",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-28 19:10
|
||||
|
||||
from django.db import migrations
|
||||
from django.utils.text import slugify
|
||||
|
||||
|
||||
def populate_ride_model_slugs(apps, schema_editor):
|
||||
"""Populate unique slugs for existing RideModel records."""
|
||||
RideModel = apps.get_model('rides', 'RideModel')
|
||||
Company = apps.get_model('rides', 'Company')
|
||||
|
||||
for ride_model in RideModel.objects.all():
|
||||
# Generate base slug from manufacturer name + model name
|
||||
if ride_model.manufacturer:
|
||||
base_slug = slugify(f"{ride_model.manufacturer.name} {ride_model.name}")
|
||||
else:
|
||||
base_slug = slugify(ride_model.name)
|
||||
|
||||
# Ensure uniqueness
|
||||
slug = base_slug
|
||||
counter = 1
|
||||
while RideModel.objects.filter(slug=slug).exclude(pk=ride_model.pk).exists():
|
||||
slug = f"{base_slug}-{counter}"
|
||||
counter += 1
|
||||
|
||||
# Update the slug
|
||||
ride_model.slug = slug
|
||||
ride_model.save(update_fields=['slug'])
|
||||
|
||||
|
||||
def reverse_populate_ride_model_slugs(apps, schema_editor):
|
||||
"""Reverse operation - clear slugs (not really needed but for completeness)."""
|
||||
RideModel = apps.get_model('rides', 'RideModel')
|
||||
RideModel.objects.all().update(slug='')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0010_add_comprehensive_ride_model_system"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
populate_ride_model_slugs,
|
||||
reverse_populate_ride_model_slugs,
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-28 19:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0011_populate_ride_model_slugs"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="ridemodel",
|
||||
name="slug",
|
||||
field=models.SlugField(
|
||||
help_text="URL-friendly identifier", max_length=255, unique=True
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -9,6 +9,7 @@ from django.db import models
|
||||
from django.conf import settings
|
||||
from apps.core.history import TrackedModel
|
||||
from apps.core.services.media_service import MediaService
|
||||
from cloudflare_images.field import CloudflareImagesField
|
||||
import pghistory
|
||||
|
||||
|
||||
@@ -36,9 +37,9 @@ class RidePhoto(TrackedModel):
|
||||
"rides.Ride", on_delete=models.CASCADE, related_name="photos"
|
||||
)
|
||||
|
||||
image = models.ImageField(
|
||||
upload_to=ride_photo_upload_path,
|
||||
max_length=255,
|
||||
image = CloudflareImagesField(
|
||||
variant="public",
|
||||
help_text="Ride photo stored on Cloudflare Images"
|
||||
)
|
||||
|
||||
caption = models.CharField(max_length=255, blank=True)
|
||||
@@ -73,7 +74,7 @@ class RidePhoto(TrackedModel):
|
||||
related_name="uploaded_ride_photos",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
class Meta(TrackedModel.Meta):
|
||||
app_label = "rides"
|
||||
ordering = ["-is_primary", "-created_at"]
|
||||
indexes = [
|
||||
|
||||
@@ -23,11 +23,15 @@ Categories = CATEGORY_CHOICES
|
||||
class RideModel(TrackedModel):
|
||||
"""
|
||||
Represents a specific model/type of ride that can be manufactured by different
|
||||
companies.
|
||||
For example: B&M Dive Coaster, Vekoma Boomerang, etc.
|
||||
companies. This serves as a catalog of ride designs that can be referenced
|
||||
by individual ride installations.
|
||||
|
||||
For example: B&M Dive Coaster, Vekoma Boomerang, RMC I-Box, etc.
|
||||
"""
|
||||
|
||||
name = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255, help_text="Name of the ride model")
|
||||
slug = models.SlugField(max_length=255, unique=True,
|
||||
help_text="URL-friendly identifier")
|
||||
manufacturer = models.ForeignKey(
|
||||
Company,
|
||||
on_delete=models.SET_NULL,
|
||||
@@ -35,15 +39,154 @@ class RideModel(TrackedModel):
|
||||
null=True,
|
||||
blank=True,
|
||||
limit_choices_to={"roles__contains": ["MANUFACTURER"]},
|
||||
help_text="Primary manufacturer of this ride model"
|
||||
)
|
||||
description = models.TextField(blank=True)
|
||||
description = models.TextField(
|
||||
blank=True, help_text="Detailed description of the ride model")
|
||||
category = models.CharField(
|
||||
max_length=2, choices=CATEGORY_CHOICES, default="", blank=True
|
||||
max_length=2,
|
||||
choices=CATEGORY_CHOICES,
|
||||
default="",
|
||||
blank=True,
|
||||
help_text="Primary category classification"
|
||||
)
|
||||
|
||||
# Technical specifications
|
||||
typical_height_range_min_ft = models.DecimalField(
|
||||
max_digits=6, decimal_places=2, null=True, blank=True,
|
||||
help_text="Minimum typical height in feet for this model"
|
||||
)
|
||||
typical_height_range_max_ft = models.DecimalField(
|
||||
max_digits=6, decimal_places=2, null=True, blank=True,
|
||||
help_text="Maximum typical height in feet for this model"
|
||||
)
|
||||
typical_speed_range_min_mph = models.DecimalField(
|
||||
max_digits=5, decimal_places=2, null=True, blank=True,
|
||||
help_text="Minimum typical speed in mph for this model"
|
||||
)
|
||||
typical_speed_range_max_mph = models.DecimalField(
|
||||
max_digits=5, decimal_places=2, null=True, blank=True,
|
||||
help_text="Maximum typical speed in mph for this model"
|
||||
)
|
||||
typical_capacity_range_min = models.PositiveIntegerField(
|
||||
null=True, blank=True,
|
||||
help_text="Minimum typical hourly capacity for this model"
|
||||
)
|
||||
typical_capacity_range_max = models.PositiveIntegerField(
|
||||
null=True, blank=True,
|
||||
help_text="Maximum typical hourly capacity for this model"
|
||||
)
|
||||
|
||||
# Design characteristics
|
||||
track_type = models.CharField(
|
||||
max_length=100, blank=True,
|
||||
help_text="Type of track system (e.g., tubular steel, I-Box, wooden)"
|
||||
)
|
||||
support_structure = models.CharField(
|
||||
max_length=100, blank=True,
|
||||
help_text="Type of support structure (e.g., steel, wooden, hybrid)"
|
||||
)
|
||||
train_configuration = models.CharField(
|
||||
max_length=200, blank=True,
|
||||
help_text="Typical train configuration (e.g., 2 trains, 7 cars per train, 4 seats per car)"
|
||||
)
|
||||
restraint_system = models.CharField(
|
||||
max_length=100, blank=True,
|
||||
help_text="Type of restraint system (e.g., over-shoulder, lap bar, vest)"
|
||||
)
|
||||
|
||||
# Market information
|
||||
first_installation_year = models.PositiveIntegerField(
|
||||
null=True, blank=True,
|
||||
help_text="Year of first installation of this model"
|
||||
)
|
||||
last_installation_year = models.PositiveIntegerField(
|
||||
null=True, blank=True,
|
||||
help_text="Year of last installation of this model (if discontinued)"
|
||||
)
|
||||
is_discontinued = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Whether this model is no longer being manufactured"
|
||||
)
|
||||
total_installations = models.PositiveIntegerField(
|
||||
default=0,
|
||||
help_text="Total number of installations worldwide (auto-calculated)"
|
||||
)
|
||||
|
||||
# Design features
|
||||
notable_features = models.TextField(
|
||||
blank=True,
|
||||
help_text="Notable design features or innovations (JSON or comma-separated)"
|
||||
)
|
||||
target_market = models.CharField(
|
||||
max_length=50, blank=True,
|
||||
choices=[
|
||||
('FAMILY', 'Family'),
|
||||
('THRILL', 'Thrill'),
|
||||
('EXTREME', 'Extreme'),
|
||||
('KIDDIE', 'Kiddie'),
|
||||
('ALL_AGES', 'All Ages'),
|
||||
],
|
||||
help_text="Primary target market for this ride model"
|
||||
)
|
||||
|
||||
# Media
|
||||
primary_image = models.ForeignKey(
|
||||
'RideModelPhoto',
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='ride_models_as_primary',
|
||||
help_text="Primary promotional image for this ride model"
|
||||
)
|
||||
|
||||
# SEO and metadata
|
||||
meta_title = models.CharField(
|
||||
max_length=60, blank=True,
|
||||
help_text="SEO meta title (auto-generated if blank)"
|
||||
)
|
||||
meta_description = models.CharField(
|
||||
max_length=160, blank=True,
|
||||
help_text="SEO meta description (auto-generated if blank)"
|
||||
)
|
||||
|
||||
class Meta(TrackedModel.Meta):
|
||||
ordering = ["manufacturer", "name"]
|
||||
ordering = ["manufacturer__name", "name"]
|
||||
unique_together = ["manufacturer", "name"]
|
||||
constraints = [
|
||||
# Height range validation
|
||||
models.CheckConstraint(
|
||||
name="ride_model_height_range_logical",
|
||||
condition=models.Q(typical_height_range_min_ft__isnull=True)
|
||||
| models.Q(typical_height_range_max_ft__isnull=True)
|
||||
| models.Q(typical_height_range_min_ft__lte=models.F("typical_height_range_max_ft")),
|
||||
violation_error_message="Minimum height cannot exceed maximum height",
|
||||
),
|
||||
# Speed range validation
|
||||
models.CheckConstraint(
|
||||
name="ride_model_speed_range_logical",
|
||||
condition=models.Q(typical_speed_range_min_mph__isnull=True)
|
||||
| models.Q(typical_speed_range_max_mph__isnull=True)
|
||||
| models.Q(typical_speed_range_min_mph__lte=models.F("typical_speed_range_max_mph")),
|
||||
violation_error_message="Minimum speed cannot exceed maximum speed",
|
||||
),
|
||||
# Capacity range validation
|
||||
models.CheckConstraint(
|
||||
name="ride_model_capacity_range_logical",
|
||||
condition=models.Q(typical_capacity_range_min__isnull=True)
|
||||
| models.Q(typical_capacity_range_max__isnull=True)
|
||||
| models.Q(typical_capacity_range_min__lte=models.F("typical_capacity_range_max")),
|
||||
violation_error_message="Minimum capacity cannot exceed maximum capacity",
|
||||
),
|
||||
# Installation years validation
|
||||
models.CheckConstraint(
|
||||
name="ride_model_installation_years_logical",
|
||||
condition=models.Q(first_installation_year__isnull=True)
|
||||
| models.Q(last_installation_year__isnull=True)
|
||||
| models.Q(first_installation_year__lte=models.F("last_installation_year")),
|
||||
violation_error_message="First installation year cannot be after last installation year",
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return (
|
||||
@@ -52,6 +195,211 @@ class RideModel(TrackedModel):
|
||||
else f"{self.manufacturer.name} {self.name}"
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs) -> None:
|
||||
if not self.slug:
|
||||
from django.utils.text import slugify
|
||||
base_slug = slugify(
|
||||
f"{self.manufacturer.name if self.manufacturer else ''} {self.name}")
|
||||
self.slug = base_slug
|
||||
|
||||
# Ensure uniqueness
|
||||
counter = 1
|
||||
while RideModel.objects.filter(slug=self.slug).exclude(pk=self.pk).exists():
|
||||
self.slug = f"{base_slug}-{counter}"
|
||||
counter += 1
|
||||
|
||||
# Auto-generate meta fields if blank
|
||||
if not self.meta_title:
|
||||
self.meta_title = str(self)[:60]
|
||||
if not self.meta_description:
|
||||
desc = f"{self} - {self.description[:100]}" if self.description else str(
|
||||
self)
|
||||
self.meta_description = desc[:160]
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def update_installation_count(self) -> None:
|
||||
"""Update the total installations count based on actual ride instances."""
|
||||
# Import here to avoid circular import
|
||||
from django.apps import apps
|
||||
Ride = apps.get_model('rides', 'Ride')
|
||||
self.total_installations = Ride.objects.filter(ride_model=self).count()
|
||||
self.save(update_fields=['total_installations'])
|
||||
|
||||
@property
|
||||
def installation_years_range(self) -> str:
|
||||
"""Get a formatted string of installation years range."""
|
||||
if self.first_installation_year and self.last_installation_year:
|
||||
return f"{self.first_installation_year}-{self.last_installation_year}"
|
||||
elif self.first_installation_year:
|
||||
return f"{self.first_installation_year}-present" if not self.is_discontinued else f"{self.first_installation_year}+"
|
||||
return "Unknown"
|
||||
|
||||
@property
|
||||
def height_range_display(self) -> str:
|
||||
"""Get a formatted string of height range."""
|
||||
if self.typical_height_range_min_ft and self.typical_height_range_max_ft:
|
||||
return f"{self.typical_height_range_min_ft}-{self.typical_height_range_max_ft} ft"
|
||||
elif self.typical_height_range_min_ft:
|
||||
return f"{self.typical_height_range_min_ft}+ ft"
|
||||
elif self.typical_height_range_max_ft:
|
||||
return f"Up to {self.typical_height_range_max_ft} ft"
|
||||
return "Variable"
|
||||
|
||||
@property
|
||||
def speed_range_display(self) -> str:
|
||||
"""Get a formatted string of speed range."""
|
||||
if self.typical_speed_range_min_mph and self.typical_speed_range_max_mph:
|
||||
return f"{self.typical_speed_range_min_mph}-{self.typical_speed_range_max_mph} mph"
|
||||
elif self.typical_speed_range_min_mph:
|
||||
return f"{self.typical_speed_range_min_mph}+ mph"
|
||||
elif self.typical_speed_range_max_mph:
|
||||
return f"Up to {self.typical_speed_range_max_mph} mph"
|
||||
return "Variable"
|
||||
|
||||
|
||||
@pghistory.track()
|
||||
class RideModelVariant(TrackedModel):
|
||||
"""
|
||||
Represents specific variants or configurations of a ride model.
|
||||
For example: B&M Hyper Coaster might have variants like "Mega Coaster", "Giga Coaster"
|
||||
"""
|
||||
|
||||
ride_model = models.ForeignKey(
|
||||
RideModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="variants"
|
||||
)
|
||||
name = models.CharField(max_length=255, help_text="Name of this variant")
|
||||
description = models.TextField(
|
||||
blank=True, help_text="Description of variant differences")
|
||||
|
||||
# Variant-specific specifications
|
||||
min_height_ft = models.DecimalField(
|
||||
max_digits=6, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
max_height_ft = models.DecimalField(
|
||||
max_digits=6, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
min_speed_mph = models.DecimalField(
|
||||
max_digits=5, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
max_speed_mph = models.DecimalField(
|
||||
max_digits=5, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
|
||||
# Distinguishing features
|
||||
distinguishing_features = models.TextField(
|
||||
blank=True,
|
||||
help_text="What makes this variant unique from the base model"
|
||||
)
|
||||
|
||||
class Meta(TrackedModel.Meta):
|
||||
ordering = ["ride_model", "name"]
|
||||
unique_together = ["ride_model", "name"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.ride_model} - {self.name}"
|
||||
|
||||
|
||||
@pghistory.track()
|
||||
class RideModelPhoto(TrackedModel):
|
||||
"""Photos associated with ride models for catalog/promotional purposes."""
|
||||
|
||||
ride_model = models.ForeignKey(
|
||||
RideModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="photos"
|
||||
)
|
||||
image = models.ImageField(
|
||||
upload_to="ride_models/photos/",
|
||||
help_text="Photo of the ride model"
|
||||
)
|
||||
caption = models.CharField(max_length=500, blank=True)
|
||||
alt_text = models.CharField(max_length=255, blank=True)
|
||||
|
||||
# Photo metadata
|
||||
photo_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=[
|
||||
('PROMOTIONAL', 'Promotional'),
|
||||
('TECHNICAL', 'Technical Drawing'),
|
||||
('INSTALLATION', 'Installation Example'),
|
||||
('RENDERING', '3D Rendering'),
|
||||
('CATALOG', 'Catalog Image'),
|
||||
],
|
||||
default='PROMOTIONAL'
|
||||
)
|
||||
|
||||
is_primary = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Whether this is the primary photo for the ride model"
|
||||
)
|
||||
|
||||
# Attribution
|
||||
photographer = models.CharField(max_length=255, blank=True)
|
||||
source = models.CharField(max_length=255, blank=True)
|
||||
copyright_info = models.CharField(max_length=255, blank=True)
|
||||
|
||||
class Meta(TrackedModel.Meta):
|
||||
ordering = ["-is_primary", "-created_at"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Photo of {self.ride_model.name}"
|
||||
|
||||
def save(self, *args, **kwargs) -> None:
|
||||
# Ensure only one primary photo per ride model
|
||||
if self.is_primary:
|
||||
RideModelPhoto.objects.filter(
|
||||
ride_model=self.ride_model,
|
||||
is_primary=True
|
||||
).exclude(pk=self.pk).update(is_primary=False)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
@pghistory.track()
|
||||
class RideModelTechnicalSpec(TrackedModel):
|
||||
"""
|
||||
Technical specifications for ride models that don't fit in the main model.
|
||||
This allows for flexible specification storage.
|
||||
"""
|
||||
|
||||
ride_model = models.ForeignKey(
|
||||
RideModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="technical_specs"
|
||||
)
|
||||
|
||||
spec_category = models.CharField(
|
||||
max_length=50,
|
||||
choices=[
|
||||
('DIMENSIONS', 'Dimensions'),
|
||||
('PERFORMANCE', 'Performance'),
|
||||
('CAPACITY', 'Capacity'),
|
||||
('SAFETY', 'Safety Features'),
|
||||
('ELECTRICAL', 'Electrical Requirements'),
|
||||
('FOUNDATION', 'Foundation Requirements'),
|
||||
('MAINTENANCE', 'Maintenance'),
|
||||
('OTHER', 'Other'),
|
||||
]
|
||||
)
|
||||
|
||||
spec_name = models.CharField(max_length=100, help_text="Name of the specification")
|
||||
spec_value = models.CharField(
|
||||
max_length=255, help_text="Value of the specification")
|
||||
spec_unit = models.CharField(max_length=20, blank=True,
|
||||
help_text="Unit of measurement")
|
||||
notes = models.TextField(
|
||||
blank=True, help_text="Additional notes about this specification")
|
||||
|
||||
class Meta(TrackedModel.Meta):
|
||||
ordering = ["spec_category", "spec_name"]
|
||||
unique_together = ["ride_model", "spec_category", "spec_name"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
unit_str = f" {self.spec_unit}" if self.spec_unit else ""
|
||||
return f"{self.ride_model.name} - {self.spec_name}: {self.spec_value}{unit_str}"
|
||||
|
||||
|
||||
@pghistory.track()
|
||||
class Ride(TrackedModel):
|
||||
@@ -139,6 +487,24 @@ class Ride(TrackedModel):
|
||||
max_digits=3, decimal_places=2, null=True, blank=True
|
||||
)
|
||||
|
||||
# Image settings - references to existing photos
|
||||
banner_image = models.ForeignKey(
|
||||
"RidePhoto",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="rides_using_as_banner",
|
||||
help_text="Photo to use as banner image for this ride"
|
||||
)
|
||||
card_image = models.ForeignKey(
|
||||
"RidePhoto",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="rides_using_as_card",
|
||||
help_text="Photo to use as card image for this ride"
|
||||
)
|
||||
|
||||
class Meta(TrackedModel.Meta):
|
||||
ordering = ["name"]
|
||||
unique_together = ["park", "slug"]
|
||||
|
||||
Reference in New Issue
Block a user