mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:31:07 -05:00
Add migrations for ParkPhoto and RidePhoto models with associated events
- Created ParkPhoto and ParkPhotoEvent models in the parks app, including fields for image, caption, alt text, and relationships to the Park model. - Implemented triggers for insert and update operations on ParkPhoto to log changes in ParkPhotoEvent. - Created RidePhoto and RidePhotoEvent models in the rides app, with similar structure and functionality as ParkPhoto. - Added fields for photo type in RidePhoto and implemented corresponding triggers for logging changes. - Established necessary indexes and unique constraints for both models to ensure data integrity and optimize queries.
This commit is contained in:
@@ -7,7 +7,6 @@ This module contains media models specific to parks domain.
|
||||
from typing import Any, Optional, cast
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from apps.core.history import TrackedModel
|
||||
from apps.core.services.media_service import MediaService
|
||||
import pghistory
|
||||
@@ -15,16 +14,14 @@ import pghistory
|
||||
|
||||
def park_photo_upload_path(instance: models.Model, filename: str) -> str:
|
||||
"""Generate upload path for park photos."""
|
||||
photo = cast('ParkPhoto', instance)
|
||||
photo = cast("ParkPhoto", instance)
|
||||
park = photo.park
|
||||
|
||||
if park is None:
|
||||
raise ValueError("Park cannot be None")
|
||||
|
||||
return MediaService.generate_upload_path(
|
||||
domain="park",
|
||||
identifier=park.slug,
|
||||
filename=filename
|
||||
domain="park", identifier=park.slug, filename=filename
|
||||
)
|
||||
|
||||
|
||||
@@ -33,9 +30,7 @@ class ParkPhoto(TrackedModel):
|
||||
"""Photo model specific to parks."""
|
||||
|
||||
park = models.ForeignKey(
|
||||
'parks.Park',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='photos'
|
||||
"parks.Park", on_delete=models.CASCADE, related_name="photos"
|
||||
)
|
||||
|
||||
image = models.ImageField(
|
||||
@@ -72,9 +67,9 @@ class ParkPhoto(TrackedModel):
|
||||
constraints = [
|
||||
# Only one primary photo per park
|
||||
models.UniqueConstraint(
|
||||
fields=['park'],
|
||||
fields=["park"],
|
||||
condition=models.Q(is_primary=True),
|
||||
name='unique_primary_park_photo'
|
||||
name="unique_primary_park_photo",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user