我有一个返回 json 的类
[{
'title': 'Test Blog Title 1',
'content': 'Blog Content',
'author_name': 'User 1'
},
{
'title': 'Test Blog Title 2',
'content': 'Blog Content 2',
'author_name': 'User 2'
}]
我想根据返回的 Json 创建 Tastypie 模型资源
我尝试了以下网址,但我不想声明它应该是动态的字段
http://thehungrycoder.com/python/using-non-orm-data-sources-with-tastypie-in-django.html
class BlogResource(Resource):
#i dont want the fields below instead want it to be dynamic based on json
title = fields.CharField(attribute='title')
content = fields.CharField(attribute='content')
author = fields.CharField(attribute='author_name')
class Meta:
resource_name = 'blogs'