Django 1.7 migration file cannot use user methods
I am working on a project using django 1.7. I have created a migration file and want to use User method like user.get_first_name()
and it returns
AttributeError: 'User' object has no attribute 'get_full_name'
I am importing from django.contrib.auth.models import User
but I don't think this is the reason.
Btw, I am using pdb to debug it. I have found that I can use a custom file, for example user.first_name
, user.username
but the user does not have the methods return an attribute.
Did I miss something? Or am I using something wrong?
source to share
Hmm, this method returns "%s %s" % (self.first_name, self.last_name)
. So maybe use:
def my_get_full_name(user):
return "%s %s" % (user.first_name, user.last_name)
full_name = my_get_full_name(user)
I had a similar problem. I needed a method set_password
. But I found that this method uses a make_password
function from django.contrib.auth.hashers
. So it user.password = make_password('pass')
works.
source to share