mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Support User model in Django 1.4 that has not a USERNAME_FIELD attribute
Support User model in Django 1.4 that has not a USERNAME_FIELD attribute.
This commit is contained in:
parent
43b4ae752d
commit
c63ea01f4f
|
@ -85,8 +85,13 @@ class BasicAuthentication(BaseAuthentication):
|
|||
"""
|
||||
Authenticate the userid and password against username and password.
|
||||
"""
|
||||
user_model = get_user_model()
|
||||
if hasattr(user_model, 'USERNAME_FIELD'):
|
||||
username_field = user_model.USERNAME_FIELD
|
||||
else:
|
||||
username_field = 'username'
|
||||
credentials = {
|
||||
get_user_model().USERNAME_FIELD: userid,
|
||||
username_field: userid,
|
||||
'password': password
|
||||
}
|
||||
user = authenticate(**credentials)
|
||||
|
|
Loading…
Reference in New Issue
Block a user