Files
bus-manager/busManager/migration_scripts/populate_locations.py
T
st01765 4025c28eae Added locations app
Moved contacts to new model
2026-02-26 13:34:32 +11:00

38 lines
1.1 KiB
Python

from setup_django import *
from traveller.models import Family
from locations.models import Suburb, Location
for family in Family.objects.all():
residential_address = family.residential_address
residential_suburb = family.residential_suburb
postal_address = family.postal_address
postal_suburb = family.postal_suburb
if residential_address and residential_suburb:
suburb = Suburb.objects.get(pk=residential_suburb.id)
location, created = Location.objects.get_or_create(
address=residential_address,
suburb=suburb,
)
family.location = location
if postal_address and postal_suburb:
suburb = Suburb.objects.get(pk=postal_suburb.id)
location, created = Location.objects.get_or_create(
address=postal_address,
suburb=suburb,
)
family.postal_location = location
family.save()
residential_count = Family.objects.filter(
location__isnull=False
).count()
postal_count = Family.objects.filter(
postal_location__isnull=False
).count()
print(f"Residential count: {residential_count}")
print(f"Postal count: {postal_count}")