fixed the damn discord button

This commit is contained in:
pacnpal
2024-10-31 16:13:05 +00:00
parent 0075f7da6c
commit c1591af871
31 changed files with 1184 additions and 500 deletions

View File

@@ -0,0 +1,37 @@
# Generated by Django 5.1.2 on 2024-10-30 23:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("parks", "0003_alter_historicalpark_status_alter_park_status"),
]
operations = [
migrations.AddField(
model_name="historicalpark",
name="city",
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name="historicalpark",
name="state",
field=models.CharField(
blank=True, help_text="State/Province/Region", max_length=255
),
),
migrations.AddField(
model_name="park",
name="city",
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name="park",
name="state",
field=models.CharField(
blank=True, help_text="State/Province/Region", max_length=255
),
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.1.2 on 2024-10-30 23:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("parks", "0004_historicalpark_city_historicalpark_state_park_city_and_more"),
]
operations = [
migrations.AlterField(
model_name="historicalpark",
name="country",
field=models.CharField(help_text="Country name", max_length=255),
),
migrations.AlterField(
model_name="park",
name="country",
field=models.CharField(help_text="Country name", max_length=255),
),
]

View File

@@ -0,0 +1,125 @@
from django.db import migrations, models
import django.db.models.deletion
def forwards_func(apps, schema_editor):
# Get the historical models
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")
# Create default country for existing parks
default_country, _ = Country.objects.get_or_create(
name='Unknown',
name_ascii='Unknown',
slug='unknown',
code2='XX'
)
# Store old values
parks_data = []
for park in Park.objects.all():
parks_data.append({
'id': park.id,
'old_country': park.country,
'old_state': park.state,
'location': park.location
})
# Remove old fields first
Park._meta.get_field('country').null = True
Park._meta.get_field('state').null = True
Park.objects.all().update(country=None, state=None)
# Now update with new values
for data in parks_data:
park = Park.objects.get(id=data['id'])
park.country_id = default_country.id
park.save()
def reverse_func(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('cities_light', '0011_alter_city_country_alter_city_region_and_more'),
('parks', '0005_update_country_field_length'),
]
operations = [
# First make the fields nullable
migrations.AlterField(
model_name='park',
name='country',
field=models.CharField(max_length=255, null=True),
),
migrations.AlterField(
model_name='historicalpark',
name='country',
field=models.CharField(max_length=255, null=True),
),
migrations.AlterField(
model_name='park',
name='state',
field=models.CharField(max_length=255, null=True),
),
migrations.AlterField(
model_name='historicalpark',
name='state',
field=models.CharField(max_length=255, null=True),
),
# Run the data migration
migrations.RunPython(forwards_func, reverse_func),
# Remove old fields
migrations.RemoveField(
model_name='park',
name='state',
),
migrations.RemoveField(
model_name='historicalpark',
name='state',
),
migrations.RemoveField(
model_name='park',
name='country',
),
migrations.RemoveField(
model_name='historicalpark',
name='country',
),
# Add new fields
migrations.AddField(
model_name='park',
name='country',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='cities_light.country'),
),
migrations.AddField(
model_name='park',
name='region',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cities_light.region'),
),
migrations.AddField(
model_name='park',
name='city',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cities_light.city'),
),
migrations.AddField(
model_name='historicalpark',
name='country',
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='cities_light.country'),
),
migrations.AddField(
model_name='historicalpark',
name='region',
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='cities_light.region'),
),
migrations.AddField(
model_name='historicalpark',
name='city',
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='cities_light.city'),
),
]