Django tastypie: Resource show different in detailed request as in list request

我的未来我决定 提交于 2019-12-05 07:57:01

There is a feature request for different fields in show and index, alnong with some discussion how it could be implemented:

https://github.com/toastdriven/django-tastypie/issues/18

Until this feature is not included, maybe you can help with this workaround:

https://github.com/toastdriven/django-tastypie/issues/18#issuecomment-2695447

Good news! This has been added to tastypie.

If you wish to set up a field to be only on certain pages, simply define the use_in attribute to be either 'all', 'list' or 'detail'.

More info here, but I'll provide an example for posterity:

class DocumentResource(ModelResource):
    my_field = fields.CharField(attribute='my_field', use_in='detail')

Simple as that!

By the way, I switched to another restfull django api framework see http://django-rest-framework.org/. So I Am not using tastypie anymore. Hoewever, this question and answer is probably still usefull to others.

I found django-rest-framework a lot easier and more flexibel in the way to implement it. I haven't found anything I could not do with this framework (well, it does not bring me coffee).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!