Fixed for duplicate contacts

This commit is contained in:
st01765
2026-02-26 13:52:11 +11:00
parent 4025c28eae
commit 740f092572
@@ -8,13 +8,21 @@ updated_families = 0
for family in Family.objects.all(): for family in Family.objects.all():
if family.parent_A_firstname or family.parent_A_lastname: if family.parent_A_firstname or family.parent_A_lastname:
email = family.parent_A_email.strip() if family.parent_A_email else ""
contact_A, created = ContactPerson.objects.get_or_create( contact_A, created = ContactPerson.objects.get_or_create(
first_name=family.parent_A_firstname.strip() if family.parent_A_firstname else "", 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 "", 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 "", phone=family.parent_A_phone.strip() if family.parent_A_phone else "",
email=family.parent_A_email.strip() if family.parent_A_email else "", defaults={
"email": email,
}
) )
if not created and email and not contact_A.email:
contact_A.email = email
contact_A.save(update_fields=["email"])
family.contact_A = contact_A family.contact_A = contact_A
if created: if created:
@@ -22,13 +30,21 @@ for family in Family.objects.all():
if family.parent_B_firstname or family.parent_B_lastname: if family.parent_B_firstname or family.parent_B_lastname:
email = family.parent_B_email.strip() if family.parent_B_email else ""
contact_B, created = ContactPerson.objects.get_or_create( contact_B, created = ContactPerson.objects.get_or_create(
first_name=family.parent_B_firstname.strip() if family.parent_B_firstname else "", 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 "", 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 "", phone=family.parent_B_phone.strip() if family.parent_B_phone else "",
email=family.parent_B_email.strip() if family.parent_B_email else "", defaults={
"email": email,
}
) )
if not created and email and not contact_B.email:
contact_B.email = email
contact_B.save(update_fields=["email"])
family.contact_B = contact_B family.contact_B = contact_B
if created: if created: