models.py 618 Bytes
Newer Older
Ben Waters's avatar
init  
Ben Waters committed
1 2 3
from django.db import models

# Create your models here.
4 5 6 7
from django.contrib.auth import get_user_model
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
Ben Waters's avatar
Ben Waters committed
8 9
from rest_framework import serializers
from django.contrib.auth.models import User
10 11 12 13 14

@receiver(post_save, sender=get_user_model())
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)
Ben Waters's avatar
Ben Waters committed
15 16 17 18 19

class UserSerializer(serializers.ModelSerializer):
	class Meta:
		model = User
		fields = ('id', 'username', 'email')