title: Django Rest Framework Token Authentication for Custom User Model
body: <p>I'm new to using Django Rest Framework. I have inherited a Django project that has 2 user models: <code>mods.User</code> tied to <code>AUTH_USER_MODEL</code> and <code>players.Member</code>. </p>
  
  <p>For reasons I can't get into here, they both inherit from <code>AbstractBaseUser</code> but involve different information, with only an <code>email</code> field common between them.</p>
  
  <p>I am trying to use token authentication for users in <code>players.Member</code>. I have created an endpoint <code>/players_endpoint/register</code> which successfully adds players to the database. However, after adding the player to the database, the json response comes back with <code>Cannot assign "&lt;Member: offworld_321&gt;": "Token.user" must be a "User" instance.</code></p>
  
  <p>My create view is as follows:</p>
  
  <pre><code>class MemberCreateView(generics.CreateAPIView):
      queryset = Member.objects.all()
  
      def post(self, request, format='json'):
          serializer = MemberCreateSerializer(data=request.data)
          if serializer.is_valid():
              user = serializer.save()
              if user:
                  token = Token.objects.create(user=user)
                  json = serializer.data
                  json['token'] = token.key
                  return Response(json, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>I was following the tutorial <a href="https://iheanyi.com/journal/user-registration-authentication-with-django-django-rest-framework-react-and-redux/" rel="nofollow noreferrer">here</a></p>
  
  <p>How can I make it such that upon registration, a player receives a token which will be used for authentication?</p>