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.
22 lines
782 B
22 lines
782 B
from goods_info.models import AttachmentModel
|
|
from rest_framework import serializers
|
|
|
|
|
|
class AttachmentsSerializer(serializers.ModelSerializer):
|
|
"""
|
|
附件和图片的序列化器
|
|
"""
|
|
# source 如果是字段,会显示字段,如果是方法,会执行方法,不用加括号
|
|
# 附件或者图片的文件名
|
|
file_name = serializers.CharField(source='a_file.name', read_only=True)
|
|
|
|
# 附件或者图片的访问地址
|
|
file_url = serializers.CharField(source='a_file.url', read_only=True)
|
|
|
|
# 附件的文件类型(中文)
|
|
type_display = serializers.CharField(source='get_a_type_display', read_only=True)
|
|
|
|
class Meta:
|
|
model = AttachmentModel
|
|
fields = ['id', 'a_file', 'a_type', 'file_url', 'file_name', 'type_display']
|