From 52a02f11107c3f0d711742b8ca65b75175b79d6a Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 16 Sep 2012 13:46:10 +0800 Subject: [PATCH] Refactored common 'get' pattern into manager method. --- django/contrib/auth/backends.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py index 427fc1408d..d103f32eb5 100644 --- a/django/contrib/auth/backends.py +++ b/django/contrib/auth/backends.py @@ -13,9 +13,7 @@ class ModelBackend(object): def authenticate(self, username=None, password=None): try: UserModel = get_user_model() - user = UserModel.objects.get(**{ - getattr(UserModel, 'USERNAME_FIELD', 'username'): username - }) + user = UserModel.objects.get_by_natural_key(username) if user.check_password(password): return user except UserModel.DoesNotExist: @@ -111,9 +109,7 @@ class RemoteUserBackend(ModelBackend): user = self.configure_user(user) else: try: - user = UserModel.objects.get(**{ - getattr(UserModel, 'USERNAME_FIELD', 'username'): username - }) + user = UserModel.objects.get_by_natural_key(username) except UserModel.DoesNotExist: pass return user