import re with open('core/admin.py', 'r') as f: content = f.read() # Fix 1: Add voted logic to _process_voter_chunk chunk_logic = """ if defaults.get("voted") is True: defaults["target_door_visit"] = False defaults["call_queue_status"] = "no_call_required" voter = existing_voters.get(vid)""" content = content.replace(' voter = existing_voters.get(vid)', chunk_logic) # Fix 2: Add voted logic to _run_voter_post_import_cleanup cleanup_start = """ def _run_voter_post_import_cleanup(self, tenant): """ Runs the logic that was previously in signals but optimized for bulk. """ from django.db.models import Exists, OuterRef # 0. Ensure consistency for voters who voted Voter.objects.filter(tenant=tenant, voted=True).update( target_door_visit=False, call_queue_status='no_call_required' ) ScheduledCall.objects.filter(tenant=tenant, voter__voted=True, status='pending').update(status='cancelled') # 1. Update target_door_visit logic""" content = content.replace(' def _run_voter_post_import_cleanup(self, tenant):\n """\n Runs the logic that was previously in signals but optimized for bulk.\n """\n from django.db.models import Exists, OuterRef\n \n # 1. Update target_door_visit logic', cleanup_start) with open('core/admin.py', 'w') as f: f.write(content) print("Updated core/admin.py with voted logic in import chunks and cleanup.")