mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:31:09 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user