feat(#49): add geolocation (latitude/longitude) to municipalities
- Municipality model with optional latitude/longitude decimal fields - Municipality and brief serializers expose lat/lng (also in product_provenance of public/authenticated summaries for the Leaflet map) - seed_geography endpoint reads lat/lng and updates existing municipalities on reseed (idempotent) - TDD tests for model, serializers, summaries and seed
This commit is contained in:
@@ -92,7 +92,7 @@ class SeedGeographyView(APIView):
|
||||
if created:
|
||||
departments_created += 1
|
||||
|
||||
_, created = Municipality.objects.get_or_create(
|
||||
municipality, created = Municipality.objects.get_or_create(
|
||||
name=municipality_data["name"],
|
||||
department=department,
|
||||
defaults={"country": country},
|
||||
@@ -100,6 +100,16 @@ class SeedGeographyView(APIView):
|
||||
if created:
|
||||
municipalities_created += 1
|
||||
|
||||
latitude = municipality_data.get("latitude")
|
||||
longitude = municipality_data.get("longitude")
|
||||
if latitude is not None or longitude is not None:
|
||||
municipality.country = country
|
||||
if latitude is not None:
|
||||
municipality.latitude = latitude
|
||||
if longitude is not None:
|
||||
municipality.longitude = longitude
|
||||
municipality.save()
|
||||
|
||||
return Response(
|
||||
{
|
||||
"country": country.name,
|
||||
|
||||
Reference in New Issue
Block a user