Render "native value" in serializer

This commit is contained in:
Oliver Walters 2022-05-01 19:51:08 +10:00
parent 5d4972d981
commit 75fa0bed26
2 changed files with 17 additions and 2 deletions

View File

@ -398,6 +398,17 @@ class BaseInvenTreeSetting(models.Model):
def units(self):
return self.__class__.get_setting_units(self.key)
@property
def native_value(self):
if self.is_bool():
return self.as_bool()
if self.is_int():
return self.as_int()
return self.value
def clean(self, **kwargs):
"""
If a validator (or multiple validators) are defined for a particular setting key,
@ -636,6 +647,9 @@ class BaseInvenTreeSetting(models.Model):
return setting.get('protected', False)
@property
def protected(self):
return self.__class__.is_protected(self.key)
def settings_group_options():
"""

View File

@ -50,11 +50,12 @@ class SettingsSerializer(InvenTreeModelSerializer):
"""
Make sure protected values are not returned
"""
result = obj.value
# never return protected values
if obj.is_protected:
if obj.protected:
result = '***'
else:
result = obj.value
return result