Skip to content

Commit

Permalink
use bulk update in reverse_patient_abhanumber_relation
Browse files Browse the repository at this point in the history
  • Loading branch information
Khavin Shankar authored and Khavin Shankar committed May 20, 2024
1 parent da2dbad commit 3aa812e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions care/abdm/migrations/0013_abhanumber_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ def reverse_patient_abhanumber_relation(apps, schema_editor):
Patient = apps.get_model("facility", "PatientRegistration")
AbhaNumber = apps.get_model("abdm", "AbhaNumber")

for patient in Patient.objects.filter(abha_number__isnull=False):
abha_number = AbhaNumber.objects.get(id=patient.abha_number.id)
patients = Patient.objects.filter(abha_number__isnull=False)
abha_numbers_to_update = []

for patient in patients:
abha_number = patient.abha_number
abha_number.patient = patient
abha_number.save()
abha_numbers_to_update.append(abha_number)

AbhaNumber.objects.bulk_update(abha_numbers_to_update, ["patient"])

dependencies = [
("facility", "0432_alter_fileupload_file_type"),
Expand Down

0 comments on commit 3aa812e

Please sign in to comment.