From 81bdec45a9b4e0626745d3348d6444d6c7832d2c Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Mon, 12 Aug 2024 06:59:44 +0000 Subject: [PATCH] allows get_user_by_username to resolve user using a custom model --- apps/accounts/utils/general.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/accounts/utils/general.py b/apps/accounts/utils/general.py index 734ed053..9c891cff 100644 --- a/apps/accounts/utils/general.py +++ b/apps/accounts/utils/general.py @@ -133,12 +133,14 @@ def email_to_username_pretty_unique(email): return username -def get_user_by_username(username): +def get_user_by_username(username, UserModel=None): """Gets a user by `username` Returns None if not found """ - UserModel = get_user_model() + if UserModel is None: + UserModel = get_user_model() + try: user = UserModel.objects.get(username=username) except UserModel.DoesNotExist: