import os import sys import django # Set up Django environment sys.path.append(os.path.dirname(os.path.abspath(__file__))) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') django.setup() from interview.models import Applicant # Delete all but the first 8 applicants applicants = Applicant.objects.order_by('id') if applicants.count() > 8: ids_to_keep = list(applicants.values_list('id', flat=True)[:8]) deleted_count, _ = Applicant.objects.exclude(id__in=ids_to_keep).delete() print(f"Deleted {deleted_count} applicants. DB now has {Applicant.objects.count()} applicants.") else: print(f"DB already has {Applicant.objects.count()} applicants. No cleanup needed.")