diff --git a/backend/server/main/settings.py b/backend/server/main/settings.py index a885736..dab34e7 100644 --- a/backend/server/main/settings.py +++ b/backend/server/main/settings.py @@ -260,4 +260,6 @@ LOGGING = { 'propagate': False, }, }, -} \ No newline at end of file +} + +COUNTRY_REGION_JSON_VERSION = 'v2.4' \ No newline at end of file diff --git a/backend/server/worldtravel/management/commands/download-countries.py b/backend/server/worldtravel/management/commands/download-countries.py index d0929a0..48a6238 100644 --- a/backend/server/worldtravel/management/commands/download-countries.py +++ b/backend/server/worldtravel/management/commands/download-countries.py @@ -6,6 +6,8 @@ from django.db import transaction import json from django.conf import settings + +COUNTRY_REGION_JSON_VERSION = settings.COUNTRY_REGION_JSON_VERSION media_root = settings.MEDIA_ROOT @@ -38,7 +40,7 @@ class Command(BaseCommand): def handle(self, *args, **options): countries_json_path = os.path.join(settings.MEDIA_ROOT, 'countries+regions.json') if not os.path.exists(countries_json_path): - res = requests.get('https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/master/countries%2Bstates.json') + res = requests.get(f'https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/{COUNTRY_REGION_JSON_VERSION}/countries%2Bstates.json') if res.status_code == 200: with open(countries_json_path, 'w') as f: f.write(res.text) @@ -65,6 +67,7 @@ class Command(BaseCommand): country_code = country['iso2'] country_name = country['name'] country_subregion = country['subregion'] + country_capital = country['capital'] processed_country_codes.add(country_code) @@ -72,12 +75,14 @@ class Command(BaseCommand): country_obj = existing_countries[country_code] country_obj.name = country_name country_obj.subregion = country_subregion + country_obj.capital = country_capital countries_to_update.append(country_obj) else: country_obj = Country( name=country_name, country_code=country_code, - subregion=country_subregion + subregion=country_subregion, + capital=country_capital ) countries_to_create.append(country_obj) @@ -132,7 +137,7 @@ class Command(BaseCommand): Region.objects.bulk_create(regions_to_create) # Bulk update existing countries and regions - Country.objects.bulk_update(countries_to_update, ['name', 'subregion']) + Country.objects.bulk_update(countries_to_update, ['name', 'subregion', 'capital']) Region.objects.bulk_update(regions_to_update, ['name', 'country', 'longitude', 'latitude']) # Delete countries and regions that are no longer in the data diff --git a/backend/server/worldtravel/migrations/0010_country_capital.py b/backend/server/worldtravel/migrations/0010_country_capital.py new file mode 100644 index 0000000..35a2d70 --- /dev/null +++ b/backend/server/worldtravel/migrations/0010_country_capital.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.8 on 2024-09-11 19:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('worldtravel', '0009_alter_country_country_code'), + ] + + operations = [ + migrations.AddField( + model_name='country', + name='capital', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/backend/server/worldtravel/models.py b/backend/server/worldtravel/models.py index 66e10d4..f7f8f99 100644 --- a/backend/server/worldtravel/models.py +++ b/backend/server/worldtravel/models.py @@ -14,6 +14,7 @@ class Country(models.Model): name = models.CharField(max_length=100) country_code = models.CharField(max_length=2, unique=True) #iso2 code subregion = models.CharField(max_length=100, blank=True, null=True) + capital = models.CharField(max_length=100, blank=True, null=True) class Meta: verbose_name = "Country" diff --git a/frontend/src/lib/components/CountryCard.svelte b/frontend/src/lib/components/CountryCard.svelte index 95fbde8..d75e3ed 100644 --- a/frontend/src/lib/components/CountryCard.svelte +++ b/frontend/src/lib/components/CountryCard.svelte @@ -5,6 +5,8 @@ import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); + import MapMarkerStar from '~icons/mdi/map-marker-star'; + export let country: Country; async function nav() { @@ -21,7 +23,12 @@

{country.name}

-
{country.subregion}
+ {#if country.subregion} +
{country.subregion}
+ {/if} + {#if country.capital} +
{country.capital}
+ {/if}
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 8fade57..4b5bb15 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -41,6 +41,7 @@ export type Country = { country_code: string; subregion: string; flag_url: string; + capital: string; }; export type Region = {