简体   繁体   English

美味的多种资源

[英]Multiple resource in tastypie

i'm using Tastypie to build an REST API. 我正在使用Tastypie构建REST API。 so i have this class : 所以我有这个课:

so i have a classe ToolBox and with tastypie i can access it by 所以我有一个Classe ToolBox,并且可以通过pastepie访问它

http://somthing.com/api/toolbox/list/ http://somthing.com/api/toolbox/list/5 http://somthing.com/api/toolbox/list/ http://somthing.com/api/toolbox/list/5

but it's possible to add new mothod like "http://somthing.com/api/toolbox/stats/5" to obtain many stats of selected toolbox ? 但是可以添加诸如“ http://somthing.com/api/toolbox/stats/5”之类的新方法来获取所选工具箱的许多统计信息吗?

or it possible to create a Stat class not based on a model to give stats on ToolBox, User and many other stats? 还是可以创建一个不基于模型的Stat类,以提供ToolBox,User和许多其他统计信息?

thank you 谢谢

You should not mix resource urls, it is hackish and probably will get overly complex. 您不应该混合使用资源url,因为它有点黑,可能会变得过于复杂。 You can use the dehydrate cycle to add non-Model fields to your existing ToolboxResource or if there is a relationship you can nest one resource within another see: this post 您可以使用脱水循环将非模型字段添加到现有的ToolboxResource中,或者如果存在关系,可以将一种资源嵌套在另一种资源中,请参见: 本文

tastypie docs: dehydrate cycle 好吃的文档:脱水循环

Yes, try this. 是的,尝试这个。 It is a decorator that helps you add custom actions to Tastypie Resources: https://github.com/thelonecabbage/django-tastypie-actions 它是一个装饰器,可帮助您将自定义操作添加到Tastypie资源: https : //github.com/thelonecabbage/django-tastypie-actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM