Let's say I have a class
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"]
}