From the tastypie tutorial:
from django.contrib.auth.models import User
from django.db import models
from tastypie.models import create_api_key
models.signals.post_save.connect(create_api_key, sender=User)
The tutorial says:
“Tastypie includes a signal function you can use to auto-create ApiKey objects.”
I don’t know where to put this code, help please.
You can put this code in
models.pyfile of the relevant app. Alternatively, you can also place it insignals.pyunder your app directory — remember to alsoimport signalsin your app’s__init__.pyfile.What this code does here is that by using signals, every time a
Useris created, an HMAC API key will be automatically created for this user [source]: