from django.core.management.base import BaseCommand from allauth.socialaccount.models import SocialApp from django.contrib.sites.models import Site from decouple import config class Command(BaseCommand): help = 'Set up social authentication applications' def handle(self, *args, **options): site = Site.objects.get_current() # Create Google OAuth2 app if it doesn't exist google_app, created = SocialApp.objects.get_or_create( provider='google', name='Google', defaults={ 'client_id': config('GOOGLE_OAUTH2_CLIENT_ID', default='your-google-client-id'), 'secret': config('GOOGLE_OAUTH2_CLIENT_SECRET', default='your-google-client-secret'), } ) google_app.sites.add(site) if created: self.stdout.write( self.style.SUCCESS('Created Google OAuth2 application') ) else: self.stdout.write( self.style.WARNING('Google OAuth2 application already exists') ) self.stdout.write( self.style.SUCCESS('Social applications setup completed!') )