AttributeError: "User" object does not have "check_password" error in Django?

I have a custom model that I am trying to authenticate with:

class User(models.Model):
    #id = models.IntegerField(primary_key=True)
    #identifier = models.CharField(max_length=40, unique=True, db_index=True)
    username = models.CharField(max_length=90, unique=True, db_index=True)
    create_time = models.DateTimeField(null=True, blank=True)
    update_time = models.DateTimeField(null=True, blank=True)
    email = models.CharField(max_length=225)
    password = models.CharField(max_length=120)
    external = models.IntegerField(null=True, blank=True)
    deleted = models.IntegerField(null=True, blank=True)
    purged = models.IntegerField(null=True, blank=True)
    form_values_id = models.IntegerField(null=True, blank=True)
    disk_usage = models.DecimalField(null=True, max_digits=16, decimal_places=0, blank=True)
    #last_login = models.DateTimeField()

    objects = UserManager()
    USERNAME_FIELD = 'username'
    #check_password(password)
    class Meta:
        db_table = u'galaxy_user'

      

I mentioned this in the settings.

AUTH_USER_MODEL = 'fileupload.user'

 #views.py
        def login_backend(request):
            if request.method == 'POST':
                username = request.POST['username']
                password = request.POST['password']
                user = authenticate(username=username, password=password)
                if user is not None:
                    login(request, user)
                    return HttpResponseRedirect('/overview/')
                else:
                    return HttpResponseRedirect('/login_backend/')
            else:
                return render_to_response('login_backend.html', context_instance=RequestContext(request))

      

However, I am getting this error:

AttributeError: 'User' object has no attribute 'check_password' error 

      

What am I doing wrong?

+3


source to share


3 answers


As described in the user documentation , your user model must inherit from django.contrib.auth.models.AbstractBaseUser

, which adds all the appropriate methods.



+4


source


The documentation for Django 1.5 (which is the first with AUTH_USER_MODEL) shows the method that an alternate user model should have, and one of them is check_password. So IMO, you have two ways to solve your problem.



  • Replace the user model correctly by providing all the required methods.
  • Forget about replacing the user model and just write a custom AUTH BACKEND without including "AUTH_USER_MODEL"
0


source


Get Django 1.5 RC . And follow these instructions about creating a custom user class.

0


source







All Articles