Django构建用户对用户消息传递系统 [英] Django building a user-to-user messaging system

查看:45
本文介绍了Django构建用户对用户消息传递系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Django为我的网站构建消息传递系统,但我不知道该怎么做.我想要的是一个系统,该系统使用户能够向其他用户发送消息,并具有一个收件箱,以查看接收到的消息和通知用户已收到消息的通知.由于这是许多网站需要的功能,因此我想在Django中已经存在一些内置功能和模板.我进行了一些研究,发现了现有的应用程序,例如django-messages或django-postman,但是关于这些应用程序,在视图中使用它的方式,自定义消息模型或模板的方式等方面的文档很少或没有..我猜这些应用程序没有得到广泛使用,因为没有关于它们的教程或精确的文档,但是我没有找到其他用于消息传递的应用程序.

I'm trying to build a messaging system for my website using Django but I don't know how to do. What I want is a system that enables a user to send a message to another user, with an inbox to see the received messages and notifications that warn the user he received messages. Since it's a feature many websites need, I guess there already exists some build-in functions and templates to do that in Django. I made some researchs and I found existing apps like django-messages or django-postman but there are little or no documentations about these apps, the ways to use it in the view, the way to customize the message model or the templates, ... . I guess these apps are not widely used since there are no tutorials about them or precise documentation, but I didn't found other apps for messaging.

总结一下我的问题,在Django中构建自定义消息传递系统的最简单方法是什么?如果它是一个应用程序,我在哪里可以找到关于它的简便易用的文档/教程?

To summarize my question, what is the easiest way to build a customizable messaging system in Django ? If it's an app, where can I find good and easy documentation/tutorial about it ?

提前谢谢!

推荐答案

如果您想快速进行&我可以建议一个简单的解决方案:

If you want a quick & simple solution I can suggest:

创建一个对话模型,该模型将使用m2m字段保存参与者和消息.创建一个消息模型,该模型将保存发件人,收件人和消息的内容以及其他元数据(发送日期,读取日期等)

Create a Conversation model which will hold participants and messages using m2m fields. Create a Message model which will hold sender, recipient and message content and other metadata (send date, read date etc.)

然后,您应该为消息创建一个保存方法,该方法将根据发件人和参与者创建一个对话对象.

Then you should create a save method for message which will create a Conversation object according to sender and participant.

剩下的就是创建一些查询集,这些查询集将过滤掉消息和对话.

The rest is creation of some querysets which will filter out messages and conversations.

这篇关于Django构建用户对用户消息传递系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆