mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:51:09 -05:00
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from django.db import migrations
|
|
|
|
def fix_null_locations(apps, schema_editor):
|
|
Park = apps.get_model('parks', 'Park')
|
|
Country = apps.get_model('cities_light', 'Country')
|
|
Region = apps.get_model('cities_light', 'Region')
|
|
City = apps.get_model('cities_light', 'City')
|
|
|
|
# Get or create default locations
|
|
default_country = Country.objects.first()
|
|
if not default_country:
|
|
default_country = Country.objects.create(
|
|
name='Unknown',
|
|
name_ascii='Unknown',
|
|
slug='unknown',
|
|
geoname_id=0,
|
|
alternate_names='',
|
|
search_names='Unknown'
|
|
)
|
|
|
|
default_region = Region.objects.filter(country=default_country).first()
|
|
if not default_region:
|
|
default_region = Region.objects.create(
|
|
name='Unknown',
|
|
name_ascii='Unknown',
|
|
slug='unknown',
|
|
geoname_id=0,
|
|
alternate_names='',
|
|
country=default_country,
|
|
display_name='Unknown',
|
|
search_names='Unknown'
|
|
)
|
|
|
|
default_city = City.objects.filter(region=default_region).first()
|
|
if not default_city:
|
|
default_city = City.objects.create(
|
|
name='Unknown',
|
|
name_ascii='Unknown',
|
|
slug='unknown',
|
|
geoname_id=0,
|
|
alternate_names='',
|
|
region=default_region,
|
|
country=default_country,
|
|
display_name='Unknown',
|
|
search_names='Unknown',
|
|
latitude=0,
|
|
longitude=0,
|
|
population=0
|
|
)
|
|
|
|
# Update parks with null locations
|
|
for park in Park.objects.filter(country__isnull=True):
|
|
park.country = default_country
|
|
park.region = default_region
|
|
park.city = default_city
|
|
park.location = 'Unknown, Unknown, Unknown'
|
|
park.save()
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('parks', '0012_merge_20241031_1635'),
|
|
('cities_light', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(fix_null_locations, reverse_code=migrations.RunPython.noop),
|
|
]
|