From c63ea01f4fde7b21bdc5722920a9d5f926a680ab Mon Sep 17 00:00:00 2001 From: Petros Moisiadis Date: Tue, 19 May 2015 19:05:50 +0300 Subject: [PATCH] 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. --- rest_framework/authentication.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 0d73a5846..617256762 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -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)