我有一个使用 Python 请求来查询启用 Tasty-Pie 的 Django 应用程序的应用程序。
我有一个名为 Application 的模型,具有相应的 Tasty-Pie 资源。
这个模型/资源有几个外键,将应用程序链接到其他模型(例如二进制、主机、托管等)
我正在使用 Tasty-Pie 过滤器来获取应用程序的子集,然后我想打印一个漂亮的应用程序表,以及来自这些相关模型的一些字段。
现在,我正在使用以下内容来获取应用程序表:
def get_applications(self, parsed_args):
r = requests.get('http://foobar.com:8000/api/v1/application/?name__iregex={0}&format=json'.format(parsed_args.applications))
print(r.url)
return r
def application_iter(self, parsed_args):
for application in self.get_applications(parsed_args).json['objects']:
yield (application['name'], application['author'], application['some_other_field'])
def take_action(self, parsed_args):
return(('Name', 'Author', 'Some Other Field),
self.application_iter_iter(parsed_args),
)
我的问题是,拉入所有相关领域的“推荐”或惯用方式是什么?有没有办法扩展上述内容来做到这一点?
我得到的印象full=True
是一种不好的做法,并且使用资源 URI 是一种更好的方法。
我怎样才能做到这一点,同时尽量减少请求和数据库命中的数量?
干杯,维克多