mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:51:09 -05:00
feat: Improve park and ride data seeding logic to avoid duplicates and enhance uniqueness
This commit is contained in:
@@ -696,24 +696,36 @@ class Command(BaseCommand):
|
|||||||
if not created:
|
if not created:
|
||||||
self.stdout.write(f' ℹ️ Using existing park: {park_name}')
|
self.stdout.write(f' ℹ️ Using existing park: {park_name}')
|
||||||
|
|
||||||
# Create park location
|
# Create park location only if it doesn't exist
|
||||||
ParkLocation.objects.create(
|
location_exists = False
|
||||||
|
try:
|
||||||
|
location_exists = hasattr(park, 'location') and park.location is not None
|
||||||
|
except Exception:
|
||||||
|
location_exists = False
|
||||||
|
|
||||||
|
if created or not location_exists:
|
||||||
|
ParkLocation.objects.get_or_create(
|
||||||
park=park,
|
park=park,
|
||||||
point=Point(lng, lat),
|
defaults={
|
||||||
street_address=f"{random.randint(100, 9999)} {park_name} Dr",
|
'point': Point(lng, lat),
|
||||||
city=city,
|
'street_address': f"{random.randint(100, 9999)} {park_name} Dr",
|
||||||
state=state,
|
'city': city,
|
||||||
country=country,
|
'state': state,
|
||||||
postal_code=f"{random.randint(10000, 99999)}" if country == 'USA' else '',
|
'country': country,
|
||||||
|
'postal_code': f"{random.randint(10000, 99999)}" if country == 'USA' else '',
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create park areas
|
# Create park areas only if park was created
|
||||||
|
if created:
|
||||||
area_names = ['Main Street', 'Fantasyland', 'Tomorrowland', 'Adventureland', 'Frontierland']
|
area_names = ['Main Street', 'Fantasyland', 'Tomorrowland', 'Adventureland', 'Frontierland']
|
||||||
for area_name in random.sample(area_names, random.randint(2, 4)):
|
for area_name in random.sample(area_names, random.randint(2, 4)):
|
||||||
ParkArea.objects.create(
|
ParkArea.objects.get_or_create(
|
||||||
park=park,
|
park=park,
|
||||||
name=area_name,
|
name=area_name,
|
||||||
description=f"Themed area within {park_name}",
|
defaults={
|
||||||
|
'description': f"Themed area within {park_name}",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
parks.append(park)
|
parks.append(park)
|
||||||
@@ -733,7 +745,8 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
for i in range(len(famous_parks), count):
|
for i in range(len(famous_parks), count):
|
||||||
park_type = random.choice(park_types)
|
park_type = random.choice(park_types)
|
||||||
park_name = f"{random.choice(['Adventure', 'Magic', 'Wonder', 'Fantasy', 'Thrill', 'Family'])} {random.choice(['World', 'Land', 'Park', 'Kingdom', 'Gardens'])}"
|
# Make park names more unique by adding a number
|
||||||
|
park_name = f"{random.choice(['Adventure', 'Magic', 'Wonder', 'Fantasy', 'Thrill', 'Family'])} {random.choice(['World', 'Land', 'Park', 'Kingdom', 'Gardens'])} {i + 1}"
|
||||||
|
|
||||||
operator = random.choice(operators)
|
operator = random.choice(operators)
|
||||||
property_owner = random.choice(property_owners) if property_owners and random.random() < 0.5 else None
|
property_owner = random.choice(property_owners) if property_owners and random.random() < 0.5 else None
|
||||||
@@ -963,50 +976,72 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Create park reviews
|
# Create park reviews
|
||||||
park_review_count = count // 2
|
park_review_count = count // 2
|
||||||
for _ in range(park_review_count):
|
created_park_reviews = 0
|
||||||
|
attempts = 0
|
||||||
|
max_attempts = park_review_count * 3 # Allow multiple attempts to avoid infinite loops
|
||||||
|
|
||||||
|
while created_park_reviews < park_review_count and attempts < max_attempts:
|
||||||
if not parks:
|
if not parks:
|
||||||
break
|
break
|
||||||
|
|
||||||
user = random.choice(users)
|
user = random.choice(users)
|
||||||
park = random.choice(parks)
|
park = random.choice(parks)
|
||||||
|
attempts += 1
|
||||||
|
|
||||||
ParkReview.objects.create(
|
# Use get_or_create to avoid duplicates
|
||||||
|
review, created = ParkReview.objects.get_or_create(
|
||||||
user=user,
|
user=user,
|
||||||
park=park,
|
park=park,
|
||||||
rating=random.randint(6, 10),
|
defaults={
|
||||||
title=f"Great visit to {park.name}",
|
'rating': random.randint(6, 10),
|
||||||
content=random.choice(review_texts),
|
'title': f"Great visit to {park.name}",
|
||||||
is_published=random.choice([True] * 9 + [False]),
|
'content': random.choice(review_texts),
|
||||||
visit_date=date(
|
'is_published': random.choice([True] * 9 + [False]),
|
||||||
|
'visit_date': date(
|
||||||
random.randint(2020, 2024),
|
random.randint(2020, 2024),
|
||||||
random.randint(1, 12),
|
random.randint(1, 12),
|
||||||
random.randint(1, 28)
|
random.randint(1, 28)
|
||||||
),
|
),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
created_park_reviews += 1
|
||||||
|
|
||||||
# Create ride reviews
|
# Create ride reviews
|
||||||
ride_review_count = count - park_review_count
|
ride_review_count = count - created_park_reviews
|
||||||
for _ in range(ride_review_count):
|
created_ride_reviews = 0
|
||||||
|
attempts = 0
|
||||||
|
max_attempts = ride_review_count * 3 # Allow multiple attempts to avoid infinite loops
|
||||||
|
|
||||||
|
while created_ride_reviews < ride_review_count and attempts < max_attempts:
|
||||||
if not rides:
|
if not rides:
|
||||||
break
|
break
|
||||||
|
|
||||||
user = random.choice(users)
|
user = random.choice(users)
|
||||||
ride = random.choice(rides)
|
ride = random.choice(rides)
|
||||||
|
attempts += 1
|
||||||
|
|
||||||
RideReview.objects.create(
|
# Use get_or_create to avoid duplicates
|
||||||
|
review, created = RideReview.objects.get_or_create(
|
||||||
user=user,
|
user=user,
|
||||||
ride=ride,
|
ride=ride,
|
||||||
rating=random.randint(6, 10),
|
defaults={
|
||||||
title=f"Awesome ride - {ride.name}",
|
'rating': random.randint(6, 10),
|
||||||
content=random.choice(review_texts),
|
'title': f"Awesome ride - {ride.name}",
|
||||||
is_published=random.choice([True] * 9 + [False]),
|
'content': random.choice(review_texts),
|
||||||
visit_date=date(
|
'is_published': random.choice([True] * 9 + [False]),
|
||||||
|
'visit_date': date(
|
||||||
random.randint(2020, 2024),
|
random.randint(2020, 2024),
|
||||||
random.randint(1, 12),
|
random.randint(1, 12),
|
||||||
random.randint(1, 28)
|
random.randint(1, 28)
|
||||||
),
|
),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
created_ride_reviews += 1
|
||||||
|
|
||||||
self.stdout.write(f' ✅ Created {count} reviews')
|
self.stdout.write(f' ✅ Created {count} reviews')
|
||||||
|
|
||||||
def create_top_lists(self, users: List[User], parks: List[Park], rides: List[Ride]) -> None:
|
def create_top_lists(self, users: List[User], parks: List[Park], rides: List[Ride]) -> None:
|
||||||
@@ -1034,9 +1069,11 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Add items to the list
|
# Add items to the list
|
||||||
for rank, coaster in enumerate(random.sample(coasters, min(len(coasters), 10)), 1):
|
for rank, coaster in enumerate(random.sample(coasters, min(len(coasters), 10)), 1):
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
content_type = ContentType.objects.get_for_model(coaster)
|
||||||
TopListItem.objects.create(
|
TopListItem.objects.create(
|
||||||
top_list=top_list,
|
top_list=top_list,
|
||||||
content_type_id=coaster._meta.pk.related_model._meta.pk,
|
content_type=content_type,
|
||||||
object_id=coaster.pk,
|
object_id=coaster.pk,
|
||||||
rank=rank,
|
rank=rank,
|
||||||
notes=f"Incredible {coaster.category} experience at {coaster.park.name}",
|
notes=f"Incredible {coaster.category} experience at {coaster.park.name}",
|
||||||
@@ -1054,9 +1091,11 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Add items to the list
|
# Add items to the list
|
||||||
for rank, park in enumerate(random.sample(parks, min(len(parks), 5)), 1):
|
for rank, park in enumerate(random.sample(parks, min(len(parks), 5)), 1):
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
content_type = ContentType.objects.get_for_model(park)
|
||||||
TopListItem.objects.create(
|
TopListItem.objects.create(
|
||||||
top_list=top_list,
|
top_list=top_list,
|
||||||
content_type_id=park._meta.pk.related_model._meta.pk,
|
content_type=content_type,
|
||||||
object_id=park.pk,
|
object_id=park.pk,
|
||||||
rank=rank,
|
rank=rank,
|
||||||
notes=f"Amazing park with great {park.park_type.lower().replace('_', ' ')} atmosphere",
|
notes=f"Amazing park with great {park.park_type.lower().replace('_', ' ')} atmosphere",
|
||||||
@@ -1121,38 +1160,14 @@ class Command(BaseCommand):
|
|||||||
"""Create sample photo records"""
|
"""Create sample photo records"""
|
||||||
self.stdout.write('📸 Creating photo records...')
|
self.stdout.write('📸 Creating photo records...')
|
||||||
|
|
||||||
# Since we don't have actual Cloudflare images, we'll create placeholder records
|
if not CloudflareImage:
|
||||||
photo_count = 0
|
self.stdout.write(' ⚠️ CloudflareImage model not available, skipping photo creation')
|
||||||
|
return
|
||||||
|
|
||||||
# Create park photos
|
# Since we don't have actual Cloudflare images, we'll skip photo creation
|
||||||
for park in random.sample(parks, min(len(parks), 5)):
|
# In a real scenario, you would need actual CloudflareImage instances
|
||||||
for i in range(random.randint(1, 3)):
|
self.stdout.write(' ⚠️ Photo creation skipped (requires actual CloudflareImage instances)')
|
||||||
ParkPhoto.objects.create(
|
self.stdout.write(' ℹ️ To create photos, you need to upload actual images to Cloudflare first')
|
||||||
park=park,
|
|
||||||
caption=f"Beautiful view of {park.name}",
|
|
||||||
alt_text=f"Photo of {park.name} theme park",
|
|
||||||
photo_type=random.choice(['ENTRANCE', 'OVERVIEW', 'ATTRACTION', 'DINING']),
|
|
||||||
is_primary=i == 0,
|
|
||||||
photographer="ThrillWiki Staff",
|
|
||||||
source="Official Park Photography",
|
|
||||||
)
|
|
||||||
photo_count += 1
|
|
||||||
|
|
||||||
# Create ride photos
|
|
||||||
for ride in random.sample(rides, min(len(rides), 10)):
|
|
||||||
for i in range(random.randint(1, 2)):
|
|
||||||
RidePhoto.objects.create(
|
|
||||||
ride=ride,
|
|
||||||
caption=f"Exciting view of {ride.name}",
|
|
||||||
alt_text=f"Photo of {ride.name} ride",
|
|
||||||
photo_type=random.choice(['ACTION', 'OVERVIEW', 'QUEUE', 'DETAIL']),
|
|
||||||
is_primary=i == 0,
|
|
||||||
photographer="ThrillWiki Staff",
|
|
||||||
source="Official Park Photography",
|
|
||||||
)
|
|
||||||
photo_count += 1
|
|
||||||
|
|
||||||
self.stdout.write(f' ✅ Created {photo_count} photo records')
|
|
||||||
|
|
||||||
def create_rankings(self, rides: List[Ride]) -> None:
|
def create_rankings(self, rides: List[Ride]) -> None:
|
||||||
"""Create ride rankings if model exists"""
|
"""Create ride rankings if model exists"""
|
||||||
|
|||||||
Reference in New Issue
Block a user