我在tastype中使用一个补丁请求来更新模型中的一个字段,但是当这个补丁通过时,我尝试附加数据库中已经存在的数据,而不是完全替换该值。你知道吗
Example: In a blog post, a user flags a post as inappropriate. You want to get this user's UserID and append it to a field, flaggedUserID. flaggedUserID will contain this user's ID along with anyone else who has flagged the post previously.
在tastype中,我很难找到一个钩子,通过这个钩子,我可以在将请求中的值复制到查询中的数据之前访问查询。我尝试了“alter\u deserialized\u detail\u data(self,request,data)”钩子,但是传递给这个函数的数据参数中的值已经被替换。你知道吗
有人有什么建议吗?你知道吗
在阅读了tastypie的源代码之后,我得出了以下解决方案:
从请求到查询的数据复制似乎发生在“update\ in\ place”函数中。通过以以下方式重写此函数,我能够实现我想要的结果:
根据目标的不同,我可能会建议你多清理一点。我只想以最基本的形式展示这段代码,而不必发布多个函数并开始迷惑人们。你知道吗
相关问题 更多 >
编程相关推荐