我想编组一个对象,以便我使用来自Flask-Restful api的Url,List和Nested获得包含链接列表的响应。
job_link_fields = {
'href': restful.fields.Url('ep1', absolute=False),
'rel': restful.fields.Url('ep2', absolute=False)
}
job_fields = {
'name': restful.fields.String,
'links': restful.fields.List(restful.fields.Nested(job_link_fields))
}
class JobDao():
def __init__(self, id, job):
self.name = job['name']
self.links = [{'rel': 'jobs', 'id': id},
{'rel': 'jobs', 'id': id}]
class Job(restful.Resource):
@marshal_with(job_fields)
def get(self, id):
return JobDao(id, jobs[id-1])
但是在Url类中,我需要在构造函数中指定端点,这阻止我在List中添加differend job_link_fields。如何创建链接列表?