Set User's stringification

newer-dal
LEdoian 4 years ago
parent 434266f802
commit 206377b58b

@ -3,4 +3,11 @@ from django.contrib.auth.models import AbstractUser
# https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project # https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project
class MyUser(AbstractUser): class MyUser(AbstractUser):
pass
def __str__(self):
if self.first_name != '' and self.last_name != '':
return f"{self.first_name} {self.last_name}"
# Hack: if a nickname is to be used, it is the first name.
if self.first_name != '':
return self.first_name
return self.username

Loading…
Cancel
Save