Added locations app
Moved contacts to new model
This commit is contained in:
@@ -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}")
|
||||
Reference in New Issue
Block a user