问题
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:
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.
来源:https://stackoverflow.com/questions/59581141/django-building-a-user-to-user-messaging-system