mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 13:35:19 -05:00
lol
This commit is contained in:
@@ -235,3 +235,46 @@ def update_ride_search_text_on_ride_model_change(sender, instance, **kwargs):
|
||||
update_ride_search_text(ride)
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to update ride search_text on ride model change: {e}")
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Automatic Name History Tracking
|
||||
# =============================================================================
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Ride)
|
||||
def track_ride_name_changes(sender, instance, **kwargs):
|
||||
"""
|
||||
Automatically create RideNameHistory when a ride's name changes.
|
||||
|
||||
This ensures versioning is automatic - when a ride is renamed,
|
||||
the previous name is preserved in the name history.
|
||||
"""
|
||||
if not instance.pk:
|
||||
return # Skip new rides
|
||||
|
||||
try:
|
||||
old_instance = Ride.objects.get(pk=instance.pk)
|
||||
|
||||
if old_instance.name != instance.name:
|
||||
from .models import RideNameHistory
|
||||
|
||||
current_year = timezone.now().year
|
||||
|
||||
# Create history entry for the old name
|
||||
RideNameHistory.objects.create(
|
||||
ride=instance,
|
||||
former_name=old_instance.name,
|
||||
to_year=current_year,
|
||||
reason="Name changed",
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Ride {instance.pk} name changed from '{old_instance.name}' "
|
||||
f"to '{instance.name}' - history entry created"
|
||||
)
|
||||
except Ride.DoesNotExist:
|
||||
pass # New ride, no history to track
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to track name change for ride {instance.pk}: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user