mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 03:56:43 +00:00
Convert to "native value" in the serializer
This commit is contained in:
parent
4433befbdc
commit
324335a620
@ -909,6 +909,14 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
help_text=_('Settings key (must be unique - case insensitive'),
|
help_text=_('Settings key (must be unique - case insensitive'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def to_native_value(self):
|
||||||
|
"""
|
||||||
|
Return the "pythonic" value,
|
||||||
|
e.g. convert "True" to True, and "1" to 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.__class__.get_setting(self.key)
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeUserSetting(BaseInvenTreeSetting):
|
class InvenTreeUserSetting(BaseInvenTreeSetting):
|
||||||
"""
|
"""
|
||||||
@ -1119,6 +1127,14 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
|||||||
'user__id': kwargs['user'].id
|
'user__id': kwargs['user'].id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def to_native_value(self):
|
||||||
|
"""
|
||||||
|
Return the "pythonic" value,
|
||||||
|
e.g. convert "True" to True, and "1" to 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.__class__.get_setting(self.key, user=self.user)
|
||||||
|
|
||||||
|
|
||||||
class PriceBreak(models.Model):
|
class PriceBreak(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -11,9 +11,10 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from common.models import InvenTreeSetting, InvenTreeUserSetting
|
from common.models import InvenTreeSetting, InvenTreeUserSetting
|
||||||
|
|
||||||
class GlobalSettingsSerializer(InvenTreeModelSerializer):
|
|
||||||
|
class SettingsSerializer(InvenTreeModelSerializer):
|
||||||
"""
|
"""
|
||||||
Serializer for the InvenTreeSetting model
|
Base serializer for a settings object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = serializers.CharField(read_only=True)
|
key = serializers.CharField(read_only=True)
|
||||||
@ -26,13 +27,25 @@ class GlobalSettingsSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
choices = serializers.SerializerMethodField()
|
choices = serializers.SerializerMethodField()
|
||||||
|
|
||||||
def get_choices(self, obj: InvenTreeUserSetting):
|
def get_choices(self, obj):
|
||||||
"""
|
"""
|
||||||
Returns the choices available for a given item
|
Returns the choices available for a given item
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return obj.choices()
|
return obj.choices()
|
||||||
|
|
||||||
|
value = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
def get_value(self, obj):
|
||||||
|
|
||||||
|
return obj.to_native_value()
|
||||||
|
|
||||||
|
|
||||||
|
class GlobalSettingsSerializer(SettingsSerializer):
|
||||||
|
"""
|
||||||
|
Serializer for the InvenTreeSetting model
|
||||||
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InvenTreeSetting
|
model = InvenTreeSetting
|
||||||
fields = [
|
fields = [
|
||||||
@ -46,30 +59,13 @@ class GlobalSettingsSerializer(InvenTreeModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class UserSettingsSerializer(InvenTreeModelSerializer):
|
class UserSettingsSerializer(SettingsSerializer):
|
||||||
"""
|
"""
|
||||||
Serializer for the InvenTreeUserSetting model
|
Serializer for the InvenTreeUserSetting model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = serializers.CharField(read_only=True)
|
|
||||||
|
|
||||||
name = serializers.CharField(read_only=True)
|
|
||||||
|
|
||||||
description = serializers.CharField(read_only=True)
|
|
||||||
|
|
||||||
user = serializers.PrimaryKeyRelatedField(read_only=True)
|
user = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||||
|
|
||||||
type = serializers.CharField(source='setting_type', read_only=True)
|
|
||||||
|
|
||||||
choices = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_choices(self, obj: InvenTreeUserSetting):
|
|
||||||
"""
|
|
||||||
Returns the choices available for a given item
|
|
||||||
"""
|
|
||||||
|
|
||||||
return obj.choices()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InvenTreeUserSetting
|
model = InvenTreeUserSetting
|
||||||
fields = [
|
fields = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user