You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
537 B

2 years ago
from goods_info.models import UnitsModel
from rest_framework import serializers
class UnitsSerializer(serializers.ModelSerializer):
"""
计量单位的序列化器
"""
# 指定新增的属性,是从一个函数中得到值
units_name = serializers.SerializerMethodField(read_only=True)
class Meta:
model = UnitsModel
fields = ['id', 'basic_name', 'backup_name', 'delete_flag', 'units_name']
def get_units_name(self, obj):
return str(obj) # 就是调用该对象的__str__函数