Files
bus-manager/busManager/migration_scripts/copy_families.py
T
2026-02-06 13:09:14 +11:00

44 lines
1.9 KiB
Python

from setup_django import *
from coord.models import Family as OldFamily
from traveller.models import Family as NewFamily
created = skipped = 0
for old in OldFamily.objects.all():
obj, was_created = NewFamily.objects.get_or_create(
id=old.id,
defaults={
"traveller_id": old.traveller_id,
"residential_address": old.residential_address,
"residential_suburb_id": old.residential_suburb_id,
"postal_address": old.postal_address,
"postal_suburb_id": old.postal_suburb_id,
"parent_A_firstname": old.parent_A_firstname,
"parent_A_lastname": old.parent_A_lastname,
"parent_A_phone": old.parent_A_phone,
"parent_A_email": old.parent_A_email,
"parent_B_firstname": old.parent_B_firstname,
"parent_B_lastname": old.parent_B_lastname,
"parent_B_phone": old.parent_B_phone,
"parent_B_email": old.parent_B_email,
"emergency_contact_A_firstname": old.emergency_contact_A_firstname,
"emergency_contact_A_lastname": old.emergency_contact_A_lastname,
"emergency_contact_A_phone": old.emergency_contact_A_phone,
"emergency_contact_A_relation": old.emergency_contact_A_relation,
"emergency_contact_B_firstname": old.emergency_contact_B_firstname,
"emergency_contact_B_lastname": old.emergency_contact_B_lastname,
"emergency_contact_B_phone": old.emergency_contact_B_phone,
"emergency_contact_B_relation": old.emergency_contact_B_relation,
"created_on": old.created_on,
"last_edit": old.last_edit,
}
)
if was_created:
created += 1
else:
skipped += 1
print(f"Families — created: {created}, skipped: {skipped}")
print("Families:", OldFamily.objects.count(), NewFamily.objects.count())