Created
June 4, 2013 04:15
-
-
Save percyperez/5703528 to your computer and use it in GitHub Desktop.
Signal function to auto-create ApiKey objects when using tastypie ApiKeyAuthentication.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
# Work around the ImportError: cannot import name create_api_key | |
# Issue https://github.com/toastdriven/django-tastypie/issues/937 | |
class User(AbstractUser): | |
field1 | |
... | |
@receiver(post_save, sender=User) | |
def create_user_api_key(sender, **kwargs): | |
""" | |
Auto-create ApiKey objects using Tastypie's create_api_key | |
""" | |
from tastypie.models import create_api_key | |
create_api_key(User, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To anybody who got here from Google, here's an example for custom user models: