Skip to content

Instantly share code, notes, and snippets.

@perymerdeka
Created January 2, 2022 10:00
Show Gist options
  • Save perymerdeka/bdcca7b8688bdf97a100bef5dda7b881 to your computer and use it in GitHub Desktop.
Save perymerdeka/bdcca7b8688bdf97a100bef5dda7b881 to your computer and use it in GitHub Desktop.
from django.dispatch import receiver
from allauth.socialaccount.models import SocialAccount
from django.db.models.signals import pre_save
from .models import Users
@receiver(pre_save, sender=SocialAccount)
def add_username(*args, kwargs):
print('Presave')
print(f'args: {args} \n kwargs: {kwargs}')
@ihfazhillah
Copy link

@receiver(pre_save, sender=SocialAccount)
def add_username(sender, instance: SocialAccount, *args, kwargs):
    user = instance.user
    extra_data = instance.extra_data
    name = json.loads(extra_data).get("name")
    user.name = name
    user.save()
    print('Presave')
    print(f'args: {args} \n kwargs: {kwargs}')

@perymerdeka
Copy link
Author

siap mas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment