4025c28eae
Moved contacts to new model
38 lines
1.1 KiB
Python
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}") |