title: Not able to authenticate custom user model in Django
body: <p>I created an <code>Custom User model in Django</code> and you see my <code>models.py</code> below. </p>
  
  <pre><code>from django.core.exceptions import ObjectDoesNotExist
  from django.conf import settings
  from uuidfield import UUIDField
  
  class User(AbstractUser, Mixin):
      objects = HiddenUserManager()
      USERNAME_FIELD = 'username'
      # REQUIRED_FIELDS = ['email', 'password']
      api_token = UUIDField(auto=True)
      token_created_date = models.DateTimeField(auto_now_add=True)
  
      class Meta:
          unique_together = ('email', )  # must have unique email!
          app_label = 'portal'
  
      def api_token_reset(self):
          self.api_token = UUIDField(auto=True)
  </code></pre>
  
  <p>I also changed my <code>settings.py</code> file and added this line: </p>
  
  <p><code>AUTH_USER_MODEL = 'portal.User'</code> portal is the name of my app.</p>
  
  <p>I have created two <code>superusers</code> using the <code>portal.user model</code> as you can see in the below image:
  <a href="https://i.stack.imgur.com/k5gie.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k5gie.png" alt="enter image description here"></a></p>
  
  <p>The problem is when I enter my <code>username and password</code> in my index login page, it is not able to authenticate me. After creating models I have performed all the <code>migrations</code>. Why the the login page is not able to authenticate me? </p>
  
  <p>if I comment out my <code>customer user model</code> and remove this line <code>AUTH_USER_MODEL = 'portal.User'</code>, then my login page is able to authenticate me. Any idea where I am going wrong? </p>
  
  <p>My login view looks something like this :</p>
  
  <pre><code>from django.contrib.auth.views import login
  from django.http import HttpResponseRedirect
  
  def login(request, **kwargs):
      return login(request, **kwargs)
  </code></pre>
  
  <p>Could anyone help me here?</p>
  
  <p>UPDATED: Mixin class </p>
  
  <pre><code>class RequireStaffMixinView(RequireAuthMixinView):
      # Override 1) ensure staff
      # @method_decorator(staff_user_required)
      def dispatch(self, *args, **kwargs):
          if not self.request.user.is_staff:
              raise PermissionDenied
          return super(RequireAuthMixinView, self).dispatch(*args, **kwargs
  </code></pre>