Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-08-26 13:19:04 -04:00
parent bf7e0c0f40
commit 831be6a2ee
151 changed files with 16260 additions and 9137 deletions

View File

@@ -1,18 +1,21 @@
import os
from django.core.management.base import BaseCommand
from media.models import Photo
from apps.parks.models import ParkPhoto
from apps.rides.models import RidePhoto
from django.conf import settings
import shutil
class Command(BaseCommand):
help = "Move photo files to their normalized locations"
help = "Move photo files to their normalized locations for domain-specific photos"
def handle(self, *args, **kwargs):
self.stdout.write("Moving photo files to normalized locations...")
# Get all photos
photos = Photo.objects.all()
# Get all domain-specific photos
park_photos = ParkPhoto.objects.all()
ride_photos = RidePhoto.objects.all()
photos = list(park_photos) + list(ride_photos)
# Track processed files to clean up later
processed_files = set()
@@ -56,12 +59,17 @@ class Command(BaseCommand):
obj = photo.content_object
identifier = getattr(obj, "slug", obj.id)
# Get photo number
photo_number = Photo.objects.filter(
content_type=photo.content_type,
object_id=photo.object_id,
created_at__lte=photo.created_at,
).count()
# Get photo number based on photo type
if isinstance(photo, ParkPhoto):
photo_number = ParkPhoto.objects.filter(
park=photo.park,
created_at__lte=photo.created_at,
).count()
else: # RidePhoto
photo_number = RidePhoto.objects.filter(
ride=photo.ride,
created_at__lte=photo.created_at,
).count()
# Create new filename
_, ext = os.path.splitext(current_path)