2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-03 20:20:58 +00:00

Include 'setting type' in API data

This commit is contained in:
Oliver
2021-11-09 17:07:41 +11:00
parent 0374c27d7c
commit 07851f0b2c
3 changed files with 34 additions and 7 deletions

View File

@ -45,6 +45,16 @@ class BaseInvenTreeSetting(models.Model):
class Meta:
abstract = True
def save(self, *args, **kwargs):
"""
Enforce validation and clean before saving
"""
self.clean()
self.validate_unique()
super().save()
@classmethod
def allValues(cls, user=None):
"""
@ -427,6 +437,20 @@ class BaseInvenTreeSetting(models.Model):
return InvenTree.helpers.str2bool(self.value)
def setting_type(self):
"""
Return the field type identifier for this setting object
"""
if self.is_bool():
return 'boolean'
elif self.is_int():
return 'integer'
else:
return 'string'
@classmethod
def validator_is_bool(cls, validator):