class International(object):
""" International Class that stores versions and lists
countries
"""
def __init__(self, version, countrylist):
self.version = version
self.country_list = countrylist
class InternationalSerializer(serializers.Serializer):
""" Serializer for International page
Lists International countries and current version
"""
version = serializers.IntegerField(read_only=True)
country_list = CountrySerializer(many=True, read_only=True)
我有一个以这种方式设置的序列化程序,我希望使用 views.py 显示 serialized.data (这将是一个像这样的字典: { "version": xx, and "country_list": [ ] } )
我的views.py是这样设置的:
class CountryListView(generics.ListAPIView):
""" Endpoint : somedomain/international/
"""
## want to display a dictionary like the one below
{
"version": 5
"country_list" : [ { xxx } , { xxx } , { xxx } ]
}
我在这个 CountryListView 中编写什么代码来呈现像上面这样的字典?我真的不确定。