from panel.models import Poultry, PoultryHatching, CityOperator, PoultryRequest, KillHouseOperator, \
    KillHouseAllowVet, KillHousePercentage, KillHouseDriver, CityOperatorCheckRequest, KillHouseADDCAR, \
    ProvinceOperator, ProvinceCheckOperatorOutRequest, ProvinceCheckOperatorRequest, ShareOfAllocation, KillRequest, \
    KillRequestFactor, KillRequestFactorPayment, ProvinceKillRequest, KillHouseRequest, KillHouseCheckRequest, \
    KillHouseAssignmentInformation, ProvinceCheckInformation, ProvinceFactorToKillHouse, KillHouseFactorToProvince, \
    ProvinceCheckKillHouseFactor, DepositAllocation, InspectorOperator, PovinceInspector, Vet, KillHouseVet, \
    VetCheckRequest, VetFarm, VetFarmInspection, Admin, Jahad, CityJahad, ProvincialGovernment, VetSupervisor, \
    ProvinceAllowKillHouseRegisterCar, ProvinceAllowPoultryChooseKillHouse, ProvinceAllowPoultrySellFree, \
    KillHouseDailyQuota, ProvinceAutoAllocation


def update_database():
    from panel.models import KillHouse
    poultries = Poultry.objects.all()
    hatchings = PoultryHatching.objects.all()
    city_operators = CityOperator.objects.all()
    poultry_requests = PoultryRequest.objects.all()
    kill_house_operators = KillHouseOperator.objects.all()
    KillHouses = KillHouse.objects.all()
    killhouseallowvets = KillHouseAllowVet.objects.all()
    killhousepercentages = KillHousePercentage.objects.all()
    drivers = KillHouseDriver.objects.all()
    add_cars = KillHouseADDCAR.objects.all()
    city_check_requests = CityOperatorCheckRequest.objects.all()
    province_operators = ProvinceOperator.objects.all()
    province_check_out_requests = ProvinceCheckOperatorOutRequest.objects.all()
    province_check_requests = ProvinceCheckOperatorRequest.objects.all()
    share_of_allocations = ShareOfAllocation.objects.all()
    kill_requests = KillRequest.objects.all()
    kill_request_factors = KillRequestFactor.objects.all()
    kill_request_payment_factors = KillRequestFactorPayment.objects.all()
    province_kill_requests = ProvinceKillRequest.objects.all()
    kill_house_requests = KillHouseRequest.objects.all()
    kill_house_check_requests = KillHouseCheckRequest.objects.all()
    assignment_informations = KillHouseAssignmentInformation.objects.all()
    province_check_informations = ProvinceCheckInformation.objects.all()
    province_factors = ProvinceFactorToKillHouse.objects.all()
    kill_house_factors = KillHouseFactorToProvince.objects.all()
    province_check_kill_house_factors = ProvinceCheckKillHouseFactor.objects.all()
    deposit_allocations = DepositAllocation.objects.all()
    inspectors = InspectorOperator.objects.all()
    inspector_checks = PovinceInspector.objects.all()
    vets = Vet.objects.all()
    kill_house_vets = KillHouseVet.objects.all()
    vet_check_requests = VetCheckRequest.objects.all()
    vet_farms = VetFarm.objects.all()
    vet_farm_inspections = VetFarmInspection.objects.all()
    admins = Admin.objects.all()
    jahads = Jahad.objects.all()
    city_jahads = CityJahad.objects.all()
    goverments = ProvincialGovernment.objects.all()
    vet_supervisers = VetSupervisor.objects.all()
    province_allow_kill_house_registers = ProvinceAllowKillHouseRegisterCar.objects.all()
    province_allow_poultry_choose_kill_houses = ProvinceAllowPoultryChooseKillHouse.objects.all()
    province_allow_poultry_auto_sell = ProvinceAllowPoultrySellFree.objects.all()
    kill_house_daily_quotas = KillHouseDailyQuota.objects.all()
    province_auto_allocations = ProvinceAutoAllocation.objects.all()

    for poultry in poultries:
        poultry.city_number = poultry.address.city.id
        poultry.city_name = poultry.address.city.name
        poultry.province_number = poultry.address.province.id
        poultry.province_name = poultry.address.province.name
        poultry.save()

    for hatching in hatchings:
        hatching.city_number = hatching.poultry.address.city.id
        hatching.city_name = hatching.poultry.address.city.name
        hatching.province_number = hatching.poultry.address.province.id
        hatching.province_name = hatching.poultry.address.province.name
        hatching.save()

    for city_operator in city_operators:
        city_operator.city_number = city_operator.address.city.id
        city_operator.city_name = city_operator.address.city.name
        city_operator.province_number = city_operator.address.province.id
        city_operator.province_name = city_operator.address.province.name
        city_operator.save()

    for poultry_request in poultry_requests:
        poultry_request.city_number = poultry_request.poultry.address.city.id
        poultry_request.city_name = poultry_request.poultry.address.city.name
        poultry_request.province_number = poultry_request.poultry.address.province.id
        poultry_request.province_name = poultry_request.poultry.address.province.name
        poultry_request.save()

    for kill_house_operator in kill_house_operators:
        kill_house_operator.city_number = kill_house_operator.address.city.id
        kill_house_operator.city_name = kill_house_operator.address.city.name
        kill_house_operator.province_number = kill_house_operator.address.province.id
        kill_house_operator.province_name = kill_house_operator.address.province.name
        kill_house_operator.save()

    for KillHouse in KillHouses:
        KillHouse.city_number = KillHouse.system_address.city.id
        KillHouse.city_name = KillHouse.system_address.city.name
        KillHouse.province_number = KillHouse.system_address.province.id
        KillHouse.province_name = KillHouse.system_address.province.name
        KillHouse.save()

    for killhouseallowvet in killhouseallowvets:
        killhouseallowvet.city_number = killhouseallowvet.kill_house.system_address.city.id
        killhouseallowvet.city_name = killhouseallowvet.kill_house.system_address.city.name
        killhouseallowvet.province_number = killhouseallowvet.kill_house.system_address.province.id
        killhouseallowvet.province_name = killhouseallowvet.kill_house.system_address.province.name
        killhouseallowvet.save()

    for killhousepercentage in killhousepercentages:
        killhousepercentage.city_number = killhousepercentage.kill_house.system_address.city.id
        killhousepercentage.city_name = killhousepercentage.kill_house.system_address.city.name
        killhousepercentage.province_number = killhousepercentage.kill_house.system_address.province.id
        killhousepercentage.province_name = killhousepercentage.kill_house.system_address.province.name
        killhousepercentage.save()

    for driver in drivers:
        driver.city_number = driver.user.city.id
        driver.city_name = driver.user.city.name
        driver.province_number = driver.user.province.id
        driver.province_name = driver.user.province.name
        driver.save()

    for add_car in add_cars:
        add_car.city_number = add_car.driver.user.city.id
        add_car.city_name = add_car.driver.user.city.name
        add_car.province_number = add_car.driver.user.province.id
        add_car.province_name = add_car.driver.user.province.name
        add_car.save()

    for city_check_request in city_check_requests:
        city_check_request.city_number = city_check_request.city_operator_system.user.city.id
        city_check_request.city_name = city_check_request.city_operator_system.user.city.name
        city_check_request.province_number = city_check_request.city_operator_system.user.province.id
        city_check_request.province_name = city_check_request.city_operator_system.user.province.name
        city_check_request.save()

    for province_operator in province_operators:
        province_operator.city_number = province_operator.user.city.id
        province_operator.city_name = province_operator.user.city.name
        province_operator.province_number = province_operator.user.province.id
        province_operator.province_name = province_operator.user.province.name
        province_operator.save()

    for province_check_out_request in province_check_out_requests:
        province_check_out_request.city_number = province_check_out_request.province_operator_system.user.city.id
        province_check_out_request.city_name = province_check_out_request.province_operator_system.user.city.name
        province_check_out_request.province_number = province_check_out_request.province_operator_system.user.province.id
        province_check_out_request.province_name = province_check_out_request.province_operator_system.user.province.name
        province_check_out_request.save()

    for province_check_request in province_check_requests:
        province_check_request.city_number = province_check_request.province_operator_system.user.city.id
        province_check_request.city_name = province_check_request.province_operator_system.user.city.name
        province_check_request.province_number = province_check_request.province_operator_system.user.province.id
        province_check_request.province_name = province_check_request.province_operator_system.user.province.name
        province_check_request.save()

    for share_of_allocation in share_of_allocations:
        share_of_allocation.province_number = share_of_allocation.province.id
        share_of_allocation.province_name = share_of_allocation.province.name
        share_of_allocation.save()

    for kill_request in kill_requests:
        kill_request.city_number = kill_request.kill_house.system_address.city.id
        kill_request.city_name = kill_request.kill_house.system_address.city.name
        kill_request.province_number = kill_request.kill_house.system_address.province.id
        kill_request.province_name = kill_request.kill_house.system_address.province.name
        kill_request.save()

    for kill_request_factor in kill_request_factors:
        kill_request_factor.city_number = kill_request_factor.kill_request.kill_house.system_address.city.id
        kill_request_factor.city_name = kill_request_factor.kill_request.kill_house.system_address.city.name
        kill_request_factor.province_number = kill_request_factor.kill_request.kill_house.system_address.province.id
        kill_request_factor.province_name = kill_request_factor.kill_request.kill_house.system_address.province.name
        kill_request_factor.save()

    for kill_request_payment_factor in kill_request_payment_factors:
        kill_request_payment_factor.city_number = kill_request_payment_factor.kill_request_factor.kill_request.kill_house.system_address.city.id
        kill_request_payment_factor.city_name = kill_request_payment_factor.kill_request_factor.kill_request.kill_house.system_address.city.name
        kill_request_payment_factor.province_number = kill_request_payment_factor.kill_request_factor.kill_request.kill_house.system_address.province.id
        kill_request_payment_factor.province_name = kill_request_payment_factor.kill_request_factor.kill_request.kill_house.system_address.province.name
        kill_request_payment_factor.save()

    for province_kill_request in province_kill_requests:
        province_kill_request.city_number = province_kill_request.kill_request.kill_house.system_address.city.id
        province_kill_request.city_name = province_kill_request.kill_request.kill_house.system_address.city.name
        province_kill_request.province_number = province_kill_request.kill_request.kill_house.system_address.province.id
        province_kill_request.province_name = province_kill_request.kill_request.kill_house.system_address.province.name
        province_kill_request.save()

    for kill_house_request in kill_house_requests:
        kill_house_request.city_number = kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        kill_house_request.city_name = kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        kill_house_request.province_number = kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        kill_house_request.province_name = kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        kill_house_request.save()

    for kill_house_check_request in kill_house_check_requests:
        kill_house_check_request.city_number = kill_house_check_request.province_kill_request.kill_request.kill_house.system_address.city.id
        kill_house_check_request.city_name = kill_house_check_request.province_kill_request.kill_request.kill_house.system_address.city.name
        kill_house_check_request.province_number = kill_house_check_request.province_kill_request.kill_request.kill_house.system_address.province.id
        kill_house_check_request.province_name = kill_house_check_request.province_kill_request.kill_request.kill_house.system_address.province.name
        kill_house_check_request.save()

    for assignment_information in assignment_informations:
        assignment_information.city_number = assignment_information.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        assignment_information.city_name = assignment_information.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        assignment_information.province_number = assignment_information.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        assignment_information.province_name = assignment_information.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        assignment_information.save()

    for province_check_information in province_check_informations:
        province_check_information.city_number = province_check_information.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        province_check_information.city_name = province_check_information.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        province_check_information.province_number = province_check_information.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        province_check_information.province_name = province_check_information.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        province_check_information.save()

    for province_factor in province_factors:
        province_factor.city_number = province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        province_factor.city_name = province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        province_factor.province_number = province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        province_factor.province_name = province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        province_factor.save()

    for kill_house_factor in kill_house_factors:
        kill_house_factor.city_number = kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        kill_house_factor.city_name = kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        kill_house_factor.province_number = kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        kill_house_factor.province_name = kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        kill_house_factor.save()

    for province_check_kill_house_factor in province_check_kill_house_factors:
        province_check_kill_house_factor.city_number = province_check_kill_house_factor.kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.id
        province_check_kill_house_factor.city_name = province_check_kill_house_factor.kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.city.name
        province_check_kill_house_factor.province_number = province_check_kill_house_factor.kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.id
        province_check_kill_house_factor.province_name = province_check_kill_house_factor.kill_house_factor.province_factor.province_check_info.kill_house_assignment.kill_house_request.province_kill_request.kill_request.kill_house.system_address.province.name
        province_check_kill_house_factor.save()

    for deposit_allocation in deposit_allocations:
        deposit_allocation.city_number = deposit_allocation.poultry.poultry.address.city.id
        deposit_allocation.city_name = deposit_allocation.poultry.poultry.address.city.name
        deposit_allocation.province_number = deposit_allocation.poultry.poultry.address.province.id
        deposit_allocation.province_name = deposit_allocation.poultry.poultry.address.province.name
        deposit_allocation.save()

    for inspector in inspectors:
        inspector.city_number = inspector.address.city.id
        inspector.city_name = inspector.address.city.name
        inspector.province_number = inspector.address.province.id
        inspector.province_name = inspector.address.province.name
        inspector.save()

    for inspector_check in inspector_checks:
        inspector_check.city_number = inspector_check.poultry_request.poultry.address.city.id
        inspector_check.city_name = inspector_check.poultry_request.poultry.address.city.name
        inspector_check.province_number = inspector_check.poultry_request.poultry.address.province.id
        inspector_check.province_name = inspector_check.poultry_request.poultry.address.province.name
        inspector_check.save()

    for vet in vets:
        vet.city_number = vet.user.city.id
        vet.city_name = vet.user.city.name
        vet.province_number = vet.user.province.id
        vet.province_name = vet.user.province.name
        vet.save()

    for kill_house_vet in kill_house_vets:
        kill_house_vet.city_number = kill_house_vet.vet.user.city.id
        kill_house_vet.city_name = kill_house_vet.vet.user.city.name
        kill_house_vet.province_number = kill_house_vet.vet.user.province.id
        kill_house_vet.province_name = kill_house_vet.vet.user.province.name
        kill_house_vet.save()

    for vet_check_request in vet_check_requests:
        vet_check_request.city_number = vet_check_request.kill_house_vet.vet.user.city.id
        vet_check_request.city_name = vet_check_request.kill_house_vet.vet.user.city.name
        vet_check_request.province_number = vet_check_request.kill_house_vet.vet.user.province.id
        vet_check_request.province_name = vet_check_request.kill_house_vet.vet.user.province.name
        vet_check_request.save()

    for vet_farm in vet_farms:
        vet_farm.city_number = vet_farm.poultry.address.city.id
        vet_farm.city_name = vet_farm.poultry.address.city.name
        vet_farm.province_number = vet_farm.poultry.address.province.id
        vet_farm.province_name = vet_farm.poultry.address.province.name
        vet_farm.save()

    for vet_farm_inspection in vet_farm_inspections:
        vet_farm_inspection.city_number = vet_farm_inspection.poultry_hatching.poultry.address.city.id
        vet_farm_inspection.city_name = vet_farm_inspection.poultry_hatching.poultry.address.city.name
        vet_farm_inspection.province_number = vet_farm_inspection.poultry_hatching.poultry.address.province.id
        vet_farm_inspection.province_name = vet_farm_inspection.poultry_hatching.poultry.address.province.name
        vet_farm_inspection.save()

    for admin in admins:
        admin.city_number = admin.user.city.id
        admin.city_name = admin.user.city.name
        admin.province_number = admin.user.province.id
        admin.province_name = admin.user.province.name
        admin.save()

    for jahad in jahads:
        jahad.city_number = jahad.user.city.id
        jahad.city_name = jahad.user.city.name
        jahad.province_number = jahad.user.province.id
        jahad.province_name = jahad.user.province.name
        jahad.save()

    for city_jahad in city_jahads:
        city_jahad.city_number = city_jahad.user.city.id
        city_jahad.city_name = city_jahad.user.city.name
        city_jahad.province_number = city_jahad.user.province.id
        city_jahad.province_name = city_jahad.user.province.name
        city_jahad.save()

    for goverment in goverments:
        goverment.city_number = goverment.user.city.id
        goverment.city_name = goverment.user.city.name
        goverment.province_number = goverment.user.province.id
        goverment.province_name = goverment.user.province.name
        goverment.save()

    for vet_superviser in vet_supervisers:
        vet_superviser.city_number = vet_superviser.user.city.id
        vet_superviser.city_name = vet_superviser.user.city.name
        vet_superviser.province_number = vet_superviser.user.province.id
        vet_superviser.province_name = vet_superviser.user.province.name
        vet_superviser.save()

    for province_allow_kill_house_register in province_allow_kill_house_registers:
        province_allow_kill_house_register.city_number = province_allow_kill_house_register.kill_house.system_address.city.id
        province_allow_kill_house_register.city_name = province_allow_kill_house_register.kill_house.system_address.city.name
        province_allow_kill_house_register.province_number = province_allow_kill_house_register.kill_house.system_address.province.id
        province_allow_kill_house_register.province_name = province_allow_kill_house_register.kill_house.system_address.province.name
        province_allow_kill_house_register.save()

    for province_allow_poultry_choose_kill_house in province_allow_poultry_choose_kill_houses:
        province_allow_poultry_choose_kill_house.city_number = province_allow_poultry_choose_kill_house.poultry.address.city.id
        province_allow_poultry_choose_kill_house.city_name = province_allow_poultry_choose_kill_house.poultry.address.city.name
        province_allow_poultry_choose_kill_house.province_number = province_allow_poultry_choose_kill_house.poultry.address.province.id
        province_allow_poultry_choose_kill_house.province_name = province_allow_poultry_choose_kill_house.poultry.address.province.name
        province_allow_poultry_choose_kill_house.save()

    for province_allow_poultry_auto in province_allow_poultry_auto_sell:
        province_allow_poultry_auto.city_number = province_allow_poultry_auto.poultry.address.city.id
        province_allow_poultry_auto.city_name = province_allow_poultry_auto.poultry.address.city.name
        province_allow_poultry_auto.province_number = province_allow_poultry_auto.poultry.address.province.id
        province_allow_poultry_auto.province_name = province_allow_poultry_auto.poultry.address.province.name
        province_allow_poultry_auto.save()

    for kill_house_daily_quota in kill_house_daily_quotas:
        kill_house_daily_quota.city_number = kill_house_daily_quota.kill_house.system_address.city.id
        kill_house_daily_quota.city_name = kill_house_daily_quota.kill_house.system_address.city.name
        kill_house_daily_quota.province_number = kill_house_daily_quota.kill_house.system_address.province.id
        kill_house_daily_quota.province_name = kill_house_daily_quota.kill_house.system_address.province.name
        kill_house_daily_quota.save()

    for province_auto_allocation in province_auto_allocations:
        province_auto_allocation.city_number = province_auto_allocation.daily_quota.kill_house.system_address.city.id
        province_auto_allocation.city_name = province_auto_allocation.daily_quota.kill_house.system_address.city.name
        province_auto_allocation.province_number = province_auto_allocation.daily_quota.kill_house.system_address.province.id
        province_auto_allocation.province_name = province_auto_allocation.daily_quota.kill_house.system_address.province.name
        province_auto_allocation.save()
