Skip to content

Instantly share code, notes, and snippets.

@konstin
Created February 2, 2018 15:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konstin/124aa0cea03df4cfa7e85b6a191dffa1 to your computer and use it in GitHub Desktop.
Save konstin/124aa0cea03df4cfa7e85b6a191dffa1 to your computer and use it in GitHub Desktop.
# This is based on https://gist.github.com/getup8/7862fd86f8e48781587490f25417d7b9
from allauth.socialaccount.models import SocialApp
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Updates the allauth SocialApps registered in the database based on the ' \
'SOCIALACCOUNT_PROVIDERS setting'
def handle(self, *args, **options):
for provider, config in settings.SOCIALACCOUNT_PROVIDERS.items():
_, created = SocialApp.objects.update_or_create(provider=provider, defaults={
"name": config.get('name', provider),
"client_id": config['CLIENT_ID'],
"secret": config['SECRET_KEY'],
"sites": [settings.SITE_ID]
})
if created:
message = 'Created social app: {}'
else:
message = 'Updated social app: {}'
self.stdout.write(self.style.SUCCESS(message.format(provider)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment