在tastypie中定义ResourceField是强制性的吗?

时间:2013-04-01 12:42:01

标签: django tastypie

在tastypie中,定义ResourceField是强制性的吗?

from tastypie import fields, utils
from tastypie.resources import Resource
from myapp.api.resources import ProfileResource, NoteResource


class PersonResource(Resource):
    name = fields.CharField(attribute='name')
    age = fields.IntegerField(attribute='years_old', null=True)
    created = fields.DateTimeField(readonly=True, help_text='When the person was created', default=utils.now)
    is_active = fields.BooleanField(default=True)
    profile = fields.ToOneField(ProfileResource, 'profile')
    notes = fields.ToManyField(NoteResource, 'notes', full=True)

我有一个类会返回一个dict,我想将它作为非orm数据源转换为tastypie。由于键是动态的,我无法定义字段。

0 个答案:

没有答案