perf: Storage update comment failed

pull/13974/head
feng 2024-08-14 19:15:31 +08:00 committed by Bryan
parent e13741827d
commit ac0c6ef3d5
1 changed files with 9 additions and 7 deletions

View File

@ -219,7 +219,6 @@ command_storage_type_serializer_classes_mapping = {
class BaseStorageSerializer(serializers.ModelSerializer): class BaseStorageSerializer(serializers.ModelSerializer):
storage_type_serializer_classes_mapping = {} storage_type_serializer_classes_mapping = {}
meta = MethodSerializer() meta = MethodSerializer()
comment = serializers.SerializerMethodField(label=_('Comment'))
class Meta: class Meta:
model = None model = None
@ -252,12 +251,15 @@ class BaseStorageSerializer(serializers.ModelSerializer):
serializer = serializer_class serializer = serializer_class
return serializer return serializer
@staticmethod def to_representation(self, instance):
def get_comment(obj): data = super().to_representation(instance)
need_translate_comments = {
need_translate_comments = {'Store locally': _('Store locally'), 'Do not save': _('Do not save')} 'Store locally': _('Store locally'),
comment = obj.comment 'Do not save': _('Do not save')
return need_translate_comments.get(comment, comment) }
comment = instance.comment
data['comment'] = need_translate_comments.get(comment, comment)
return data
def save(self, **kwargs): def save(self, **kwargs):
instance = super().save(**kwargs) instance = super().save(**kwargs)