VRE Backend API and Scheduler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
760 B

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Token
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_user_token(sender, instance=None, created=False, **kwargs):
"""
When a new user is created, this signal will also create a new API token for this user. So every user will have an API token.
Arguments
----------
sender : sender
The model that has triggered the signal
instance: :attr:`~django.contrib.auth.models.User`
The newly created user model data
created : boolean
Wether the object was created (True) or updated (False).
"""
if created:
Token.objects.create(user=instance)