REST功能模块-Serialization
Posted Lani
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了REST功能模块-Serialization相关的知识,希望对你有一定的参考价值。
from rest_framework import serializers
from goods.models import Goods, GoodsCategory
class GoodsCategorySerializer(serializers.ModelSerializer):
class Meta:
model = GoodsCategory
fields = "__all__"
class GoodsSerializer(serializers.ModelSerializer):
category = GoodsCategorySerializer()
class Meta:
model = Goods
# fields = ("category", "name", "market_price", "add_time", "goods_front_image") # 序列化知道字段
fields = "__all__" # __all__ 序列化所有字段
以上是关于REST功能模块-Serialization的主要内容,如果未能解决你的问题,请参考以下文章