Search code examples
pythondjangodjango-viewsdjango-appsdjango-messages

Implementation of django-directmessages application


I am trying to use django-directmessages app. It's an application to manage simple direct messages. A part of the Documentation says:

Import the Message Management API on top of your views.py

from directmessages.apps import Inbox
  • Send message: Inbox.send_message(from_user, to_user, message)
  • List all unread messages: Inbox.get_unread_messages(user)
  • Read a message (and mark as read): Inbox.read_message(message)
  • Print a message as : : Inbox.read_message_formatted(message) Print a list of all conversation partners for a user: Inbox.get_conversations(users)

  • Get a conversation between two users: Inbox.get_conversation(user1, user2, _limit_, _reversed_, _mark_read_)

How can i implement this application in my views.py file ?


Solution

  • In a views.py, you could implement it like follows:

    Have a form, which sends a post request with a message form field to an url like /chat/<id>/send, with ID being the user you want to contact.

    In your views.py, do something like:

    Inbox.send_message(request.user, User.objects.get(id), request.GET.get('message'))