Skip to content

Commit

Permalink
Use get_username for compatibility with custom user models
Browse files Browse the repository at this point in the history
Thanks to ProfessorLogout in
mawassk#13
for this suggestion.
  • Loading branch information
mpirnat committed Jul 8, 2023
1 parent a81adf0 commit 9f2de1d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ninja_apikey/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def is_valid(self):
return self.expires_at >= timezone.now()

def __str__(self):
return f"{self.user.username}<{self.prefix}>"
return f"{self.user.get_username()}<{self.prefix}>"
2 changes: 1 addition & 1 deletion ninja_apikey/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_apikey_check():
key.hashed_key = key_data.hashed_key
key.save()
assert key
assert user.username in str(key)
assert user.get_username() in str(key)
assert not check_apikey(key_data.key)
assert not check_apikey(key.prefix)
assert not check_apikey(f"{key_data.prefix}.{get_random_string(10)}")
Expand Down

0 comments on commit 9f2de1d

Please sign in to comment.