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,15 +1,13 @@
import requests
from django.core.management.base import BaseCommand
from media.models import Photo
from parks.models import Park
from rides.models import Ride
from django.contrib.contenttypes.models import ContentType
from apps.parks.models import Park, ParkPhoto
from apps.rides.models import Ride, RidePhoto
import json
from django.core.files.base import ContentFile
class Command(BaseCommand):
help = "Download photos from seed data URLs"
help = "Download photos from seed data URLs for domain-specific photo models"
def handle(self, *args, **kwargs):
self.stdout.write("Downloading photos from seed data...")
@@ -18,9 +16,6 @@ class Command(BaseCommand):
with open("parks/management/commands/seed_data.json", "r") as f:
seed_data = json.load(f)
park_content_type = ContentType.objects.get_for_model(Park)
ride_content_type = ContentType.objects.get_for_model(Ride)
# Process parks and their photos
for park_data in seed_data["parks"]:
try:
@@ -34,15 +29,11 @@ class Command(BaseCommand):
response = requests.get(photo_url, timeout=60)
if response.status_code == 200:
# Delete any existing photos for this park
Photo.objects.filter(
content_type=park_content_type,
object_id=park.id,
).delete()
ParkPhoto.objects.filter(park=park).delete()
# Create new photo record
photo = Photo(
content_type=park_content_type,
object_id=park.id,
photo = ParkPhoto(
park=park,
is_primary=idx == 1,
)
@@ -87,15 +78,11 @@ class Command(BaseCommand):
response = requests.get(photo_url, timeout=60)
if response.status_code == 200:
# Delete any existing photos for this ride
Photo.objects.filter(
content_type=ride_content_type,
object_id=ride.id,
).delete()
RidePhoto.objects.filter(ride=ride).delete()
# Create new photo record
photo = Photo(
content_type=ride_content_type,
object_id=ride.id,
photo = RidePhoto(
ride=ride,
is_primary=idx == 1,
)