Skip to content

Instantly share code, notes, and snippets.

@rayashi
Last active August 11, 2019 23:06
Show Gist options
  • Save rayashi/23e3e04957f96b86fdc80fe2ad08ee44 to your computer and use it in GitHub Desktop.
Save rayashi/23e3e04957f96b86fdc80fe2ad08ee44 to your computer and use it in GitHub Desktop.
Catching post_save signal to create a token
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment