diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py
index 69ab8decf0..e825d21ec9 100644
--- a/InvenTree/common/models.py
+++ b/InvenTree/common/models.py
@@ -1874,6 +1874,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
]
},
+ 'DISPLAY_FULL_NAMES': {
+ 'name': _('Display Users full names'),
+ 'description': _('Display Users full names instead of usernames'),
+ 'default': False,
+ 'validator': bool
+ }
}
typ = 'inventree'
diff --git a/InvenTree/templates/InvenTree/settings/global.html b/InvenTree/templates/InvenTree/settings/global.html
index 8161b5d7fd..6554faf9e6 100644
--- a/InvenTree/templates/InvenTree/settings/global.html
+++ b/InvenTree/templates/InvenTree/settings/global.html
@@ -17,6 +17,7 @@
{% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE_TITLE" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_RESTRICT_ABOUT" icon="fa-info-circle" %}
+ {% include "InvenTree/settings/setting.html" with key="DISPLAY_FULL_NAMES" icon="fa-font" %}
|
{% include "InvenTree/settings/setting.html" with key="INVENTREE_UPDATE_CHECK_INTERVAL" icon="fa-calendar-alt" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DOWNLOAD_FROM_URL" icon="fa-cloud-download-alt" %}
diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py
index 19bc91f611..4cd01439ed 100644
--- a/InvenTree/users/models.py
+++ b/InvenTree/users/models.py
@@ -6,7 +6,7 @@ import logging
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import get_user_model
-from django.contrib.auth.models import Group, Permission
+from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
@@ -21,6 +21,7 @@ from django.utils.translation import gettext_lazy as _
from rest_framework.authtoken.models import Token as AuthToken
+import common.models as common_models
import InvenTree.helpers
import InvenTree.models
from InvenTree.ready import canAppAccessDatabase
@@ -28,6 +29,22 @@ from InvenTree.ready import canAppAccessDatabase
logger = logging.getLogger("inventree")
+# OVERRIDE START
+# Overrides Django User model __str__ with a custom function to be able to change
+# string representation of a user
+def user_model_str(self):
+ """Function to override the default Django User __str__"""
+
+ if common_models.InvenTreeSetting.get_setting('DISPLAY_FULL_NAMES'):
+ if self.first_name or self.last_name:
+ return f'{self.first_name} {self.last_name}'
+ return self.username
+
+
+User.add_to_class("__str__", user_model_str) # Overriding User.__str__
+# OVERRIDE END
+
+
def default_token():
"""Generate a default value for the token"""
return ApiToken.generate_key()
@@ -785,10 +802,16 @@ class Owner(models.Model):
def __str__(self):
"""Defines the owner string representation."""
- return f'{self.owner} ({self.owner_type.name})'
+ if self.owner_type.name == 'user' and common_models.InvenTreeSetting.get_setting('DISPLAY_FULL_NAMES'):
+ display_name = self.owner.get_full_name()
+ else:
+ display_name = str(self.owner)
+ return f'{display_name} ({self.owner_type.name})'
def name(self):
"""Return the 'name' of this owner."""
+ if self.owner_type.name == 'user' and common_models.InvenTreeSetting.get_setting('DISPLAY_FULL_NAMES'):
+ return self.owner.get_full_name()
return str(self.owner)
def label(self):