from .models import Nav
class SonNavModelSerializer(serializers.ModelSerializer):
"""嵌套的子序列化器"""
class Meta:
model = Nav
fields = ["name", "icon", "link", "is_http"]
class NavModelSerializer(serializers.ModelSerializer):
"""导航序列化器"""
# 序列化器嵌套使用,必须是外键字段才可以使用序列化器嵌套
son = SonNavModelSerializer(many=True)# 当前序列化器SonNavModelSerializer为多时,使用many=True
class Meta:
model = Nav
fields = ["name","icon","link","is_http","son"]