简体   繁体   English

如何使用 Django Rest Framework 创建“添加到收藏夹”功能

[英]How to create "add to favorites" functional using Django Rest Framework

I just can't find any information about the implementation of the system of adding to favorites for registered users.我只是找不到有关为注册用户添加到收藏夹的系统实施的任何信息。

The model has a Post model.该模型具有 Post 模型。 It has a couple of fields of format String .它有几个格式为String的字段。 The author field, which indicates which user made the POST request, etc. author字段,指示哪个用户发出了POST请求等。

But how to make it so that the user can add this Post to his “favorites”, so that later you can get a JSON response with all the posts that he added to himself.但是如何做到让用户可以将此帖子添加到他的“收藏夹”中,以便稍后您可以获得包含他添加到自己的所有帖子的JSON响应。 Well, respectively, so that you can remove from favorites.好吧,分别这样你就可以从收藏夹中删除。

Are there any ideas?有什么想法吗?

您可以在Author模型中添加一个favorite_posts字段(多对多)。

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

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