Merge pull request #1283 from OddBloke/master

Add required imports to Generating Tokens example, and update with get_user_model()
This commit is contained in:
Tom Christie 2013-12-11 08:42:43 -08:00
commit 9c0da46209

View File

@ -162,10 +162,12 @@ The `curl` command line tool may be useful for testing token authenticated APIs.
If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal. If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal.
from django.contrib.auth import get_user_model
from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
@receiver(post_save, sender=User) @receiver(post_save, sender=get_user_model())
def create_auth_token(sender, instance=None, created=False, **kwargs): def create_auth_token(sender, instance=None, created=False, **kwargs):
if created: if created:
Token.objects.create(user=instance) Token.objects.create(user=instance)