import os import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') django.setup() from core.models import Voter, Tenant def check_neighborhoods(): tenants = Tenant.objects.all() for tenant in tenants: print(f"Tenant: {tenant.name}") voters = Voter.objects.filter(tenant=tenant, is_inactive=False, yard_sign='wants') households_dict = {} for voter in voters: key = (voter.address_street, voter.city, voter.state, voter.zip_code) if key not in households_dict: households_dict[key] = voter.neighborhood else: if not households_dict[key] and voter.neighborhood: households_dict[key] = voter.neighborhood total_households = len(households_dict) households_with_nb = [nb for nb in households_dict.values() if nb] households_without_nb = [nb for nb in households_dict.values() if not nb] print(f" Total Households: {total_households}") print(f" Households with Neighborhood: {len(households_with_nb)}") print(f" Households without Neighborhood: {len(households_without_nb)}") if len(households_without_nb) > 0: print(f" First 10 neighborhoods (sorted): {sorted([nb or '' for nb in households_dict.values()])[:10]}") if __name__ == "__main__": check_neighborhoods()