Django构建用户间消息系统

huangapple go评论63阅读模式
英文:

Django building a user-to-user messaging system

问题

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.

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 ?

Thanks in advance !

英文:

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.

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 ?

Thanks in advance !

答案1

得分: 2

如果您想要一个快速且简单的解决方案,我可以建议:

创建一个Conversation模型,其中包含参与者和消息,使用m2m字段。
创建一个Message模型,其中包含发送者、接收者和消息内容以及其他元数据(发送日期、阅读日期等)。

然后,您应该为消息创建一个保存方法,该方法将根据发送者和参与者创建一个Conversation对象。

其余部分是创建一些查询集,用于过滤消息和对话。

英文:

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

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.

huangapple
  • 本文由 发表于 2020年1月3日 23:25:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定