假设我有一堂课
class Tags(object):
tags = []
def __init__(self, tags):
self.tags = tags
和一个自定义列表字段
class TagsField(serializers.WritableField):
"""
Returns a list of tags, or serializes a list of tags
"""
我不太确定从这里去哪里。如何确保将博客文章序列化程序定义为
class BlogPostSerializer(serializers.Serializer):
post = CharField()
tags = TagsField
会给我一个类似于
{
"post": "Here is my blog post about python",
"tags": ["python", "django", "rest"]
}