Answer the question
In order to leave comments, you need to log in
How to make a private messaging system in Django?
In a personal project that I'm developing, I want to implement a system of private messages. Those. not quite a chat, but something simpler, without super-features, to enable contact between two user models (client-customer). Is it feasible and what is the best way to do it? I am no less interested in how to store correspondence, whether MySQL (or possibly Postgres, if I switch) will go for this.
Answer the question
In order to leave comments, you need to log in
класс Сообщение(модели.Модель):
отправитель = модели.ИностранныйКлючь(относиться_к_имени="отправленные_сообщения")
получатель = модели.ИностранныйКлючь(относиться_к_имени="полученные_сообщения")
дата_отправка = модели.ДатаВремяПоле(автоматический_сейчас_добавить=Правда)
текст_сообщения = модели.ТекстовыйПоле()
MySQL will work too.
Create two tables, one for messages (fields id, user_id, message, dialog_id), the second - for dialogs (fields id, user1_id, user2_id). user_id, user1_id and user2_id - IDs of users from the table with users.
When creating a message, add the message itself, the author's id and the dialogue's id to the first table (create a dialogue in the table with dialogues with the id of both participants in the correspondence, if it does not already exist).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question