Skip to content

Instantly share code, notes, and snippets.

@banagale
Created February 26, 2020 18:36
Show Gist options
  • Save banagale/08dcda94dc0078a1485c9b288748ec96 to your computer and use it in GitHub Desktop.
Save banagale/08dcda94dc0078a1485c9b288748ec96 to your computer and use it in GitHub Desktop.
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
# When user is created, build user profile and create payinfo instance.
# See also accounts.forms.SignupForm.signup for other signup steps
if created:
profile = Profile.objects.create(user=instance)
profile.payment_info = PaymentInfo.objects.create()
try:
instance.profile.account_type = AccountType.objects.get(name='Basic')
except AccountType.DoesNotExist:
logger.error('Required AccountType object instance Basic is not available')
instance.profile.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment