django - 使 Django 的 "user"系统具有 "friends"的最佳方法

标签 django

关闭。这个问题需要更多 focused 。它目前不接受答案。












想改善这个问题吗?更新问题,使其仅通过 editing this post 关注一个问题。

5年前关闭。




Improve this question




我正在使用 Django 的授权系统在我的应用程序上创建帐户。

使用授权系统制作“ friend ”系统的最佳方法是什么?我希望能够将用户链接在一起,但他们必须先接受好友请求,而且我还想保留他们成为好友的日期。

最佳答案

M2M 字段几乎可以让您到达那里,但只会存储关系,而不是它的创建日期。如果您可以在没有友谊日期的情况下进行管理,那会简单得多。

否则你会想要创建一个像这样的模型:

class Friendship(models.Model):
    created = models.DateTimeField(auto_now_add=True, editable=False)
    creator = models.ForeignKey(User, related_name="friendship_creator_set")
    friend = models.ForeignKey(User, related_name="friend_set")

您可能想要创建一个方法,可能在 user profile model 上来理解这些关系。理想情况下,它应该给你这样的东西:
>> User.userprofile.friends()
[{'name': "Joe", 'created': 2010-12-01},]

关于django - 使 Django 的 "user"系统具有 "friends"的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4564760/

相关文章:

python - 使用 Django 创建 "classes"

Django模型继承: Create a subclass using existing super class

jquery - 如何将 Jquery 插件添加到 django

python - 关于 Python/Django 和消息队列的建议

python -/invoice/Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> with cell(0,0) 的布局错误

python - 如何获取 http 响应代码Django 中的网址?

python - 我可以在单个项目中同时使用 Django 和 Rest Framework View 吗?

python - 如何缓存 Django Rest Framework API 调用?

python - 在 Django search_fields 上实现自定义函数

python - Django : An established connection was aborted by the software in your host machine