""" Management command to add registered emails for testing """ from django.core.management.base import BaseCommand from django.contrib.auth.models import User from support.models import RegisteredEmail class Command(BaseCommand): help = 'Add sample registered emails for testing' def handle(self, *args, **kwargs): # Get the admin user to set as added_by admin_user = User.objects.filter(is_superuser=True).first() emails_to_add = [ { 'email': 'admin@gnxsoft.com', 'company_name': 'GNX Software', 'contact_name': 'Admin User', 'notes': 'Primary admin email', }, { 'email': 'support@gnxsoft.com', 'company_name': 'GNX Software', 'contact_name': 'Support Team', 'notes': 'General support email', }, ] created_count = 0 for email_data in emails_to_add: registered_email, created = RegisteredEmail.objects.get_or_create( email=email_data['email'], defaults={ 'company_name': email_data['company_name'], 'contact_name': email_data['contact_name'], 'notes': email_data['notes'], 'added_by': admin_user, 'is_active': True, } ) if created: created_count += 1 self.stdout.write( self.style.SUCCESS(f'āœ“ Created registered email: {email_data["email"]}') ) else: self.stdout.write( self.style.WARNING(f'- Email already exists: {email_data["email"]}') ) self.stdout.write( self.style.SUCCESS(f'\nāœ“ Added {created_count} new registered emails') )