def save_delivery(self, follow_up_object, girl, user): """ The follow up and postnatal form have the same structure. Postnatal form will use this function directly while follow up will depend on whether the health worker selected 'delivery' as the action taken """ print("action taken delivery") baby_birth_date = "" baby_death_date = "" mother_death_date = "" delivery_follow_up_group = follow_up_object["delivery_followup_group"][ 0] mother_alive = delivery_follow_up_group["mother_delivery_outcomes"][ 0] == "mother_alive" baby_alive = delivery_follow_up_group["baby_delivery_outcomes"][ 0] == "baby_alive" if baby_alive: baby_birth_date = delivery_follow_up_group["baby_birth_date"][0] else: baby_death_date = delivery_follow_up_group["baby_death_date"][0] if not mother_alive: mother_death_date = delivery_follow_up_group["mother_death_date"][ 0] birth_place = delivery_follow_up_group["birth_place"][0] if birth_place == "HealthFacility": birth_place = "Health facility" delivery_action_taken = replace_underscore( delivery_follow_up_group["action_taken"][0]) used_contraceptives = "family" in delivery_action_taken try: contraceptive_group = follow_up_object["family_planning_group"][0] postnatal_care = contraceptive_group["postnatal_received"][ 0] == "yes" except Exception as e: print(e) postnatal_care = False contraceptive_group = [] print('save delivery') delivery = Delivery(girl=girl, user=user, action_taken=delivery_action_taken, postnatal_care=postnatal_care, mother_alive=mother_alive, baby_alive=baby_alive, delivery_location=birth_place) if baby_birth_date: delivery.baby_birth_date = baby_birth_date else: delivery.baby_death_date = baby_death_date if mother_death_date: delivery.mother_death_date = mother_death_date delivery.save() if used_contraceptives: self.save_family_planning_methods_in_delivery( contraceptive_group, delivery)
import openpyxl from app.models import Delivery wb = openpyxl.load_workbook('list.xlsx') ws = wb.active for r in ws.rows: name = r[0].value housetype = r[1].value news_type = r[2].value image = r[3].value etc = r[4].value item = Delivery(name=name, housetype=housetype, kind_of_news=news_type, images=image, etc=etc) item.save() print(item, 'saved')