Added locations app

Moved contacts to new model
This commit is contained in:
st01765
2026-02-26 13:34:32 +11:00
parent a24daed8f6
commit 4025c28eae
25 changed files with 576 additions and 75 deletions
@@ -0,0 +1,26 @@
from setup_django import *
from coord.models import Suburb as OldSuburb
from common.models import Suburb as NewSuburb
created = 0
skipped = 0
for old in OldSuburb.objects.all():
obj, was_created = NewSuburb.objects.get_or_create(
id=old.id,
defaults={
"name": old.name,
"state": old.state,
"postcode": old.postcode,
"distance": old.distance,
}
)
if was_created:
created += 1
else:
skipped += 1
print(f"Created: {created}, Skipped: {skipped}")
+2 -2
View File
@@ -1,7 +1,7 @@
from setup_django import *
from coord.models import Suburb as OldSuburb
from common.models import Suburb as NewSuburb
from common.models import Suburb as OldSuburb
from locations.models import Suburb as NewSuburb
created = 0
skipped = 0
@@ -0,0 +1,73 @@
from setup_django import *
from traveller.models import Family, ContactPerson
created_contacts = 0
updated_families = 0
for family in Family.objects.all():
if family.parent_A_firstname or family.parent_A_lastname:
contact_A, created = ContactPerson.objects.get_or_create(
first_name=family.parent_A_firstname.strip() if family.parent_A_firstname else "",
last_name=family.parent_A_lastname.strip() if family.parent_A_lastname else "",
phone=family.parent_A_phone.strip() if family.parent_A_phone else "",
email=family.parent_A_email.strip() if family.parent_A_email else "",
)
family.contact_A = contact_A
if created:
created_contacts += 1
if family.parent_B_firstname or family.parent_B_lastname:
contact_B, created = ContactPerson.objects.get_or_create(
first_name=family.parent_B_firstname.strip() if family.parent_B_firstname else "",
last_name=family.parent_B_lastname.strip() if family.parent_B_lastname else "",
phone=family.parent_B_phone.strip() if family.parent_B_phone else "",
email=family.parent_B_email.strip() if family.parent_B_email else "",
)
family.contact_B = contact_B
if created:
created_contacts += 1
# -------------------------
# Emergency A
# -------------------------
if family.emergency_contact_A_firstname or family.emergency_contact_A_lastname:
contact_EA, created = ContactPerson.objects.get_or_create(
first_name=family.emergency_contact_A_firstname.strip() if family.emergency_contact_A_firstname else "",
last_name=family.emergency_contact_A_lastname.strip() if family.emergency_contact_A_lastname else "",
phone=family.emergency_contact_A_phone.strip() if family.emergency_contact_A_phone else "",
)
family.emergency_contact_A = contact_EA
if created:
created_contacts += 1
# -------------------------
# Emergency B
# -------------------------
if family.emergency_contact_B_firstname or family.emergency_contact_B_lastname:
contact_EB, created = ContactPerson.objects.get_or_create(
first_name=family.emergency_contact_B_firstname.strip() if family.emergency_contact_B_firstname else "",
last_name=family.emergency_contact_B_lastname.strip() if family.emergency_contact_B_lastname else "",
phone=family.emergency_contact_B_phone.strip() if family.emergency_contact_B_phone else "",
)
family.emergency_contact_B = contact_EB
if created:
created_contacts += 1
family.save()
updated_families += 1
print(f"Families updated: {updated_families}")
print(f"Contacts created: {created_contacts}")
@@ -0,0 +1,38 @@
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}")