Hi,
I am django postman for user to user messaging. I want to push notification to user when a new message is received. I am using angular in front end. I tried the following:
models.py
class Message(SelfPublishModel, models.Model):
SUBJECT_MAX_LENGTH = 120
serializerclass = MessageSerializer
subject = models.CharField(("subject"), max_length=SUBJECT_MAXLENGTH)
body = models.TextField(("body"), blank=True)
sender = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='sent_messages', null=True, blank=True, verbosename=("sender"))
recipient = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='received_messages', null=True, blank=True, verbosename=("recipient"))
email = models.EmailField(_("visitor"), blank=True) # instead of either sender or recipient, for an AnonymousUser
parent = models.ForeignKey('self', related_name='next_messages', null=True, blank=True, verbosename=("parent message"))
thread = models.ForeignKey('self', related_name='child_messages', null=True, blank=True, verbosename=("root message"))
sentat = models.DateTimeField(("sent at"), default=now)
readat = models.DateTimeField(("read at"), null=True, blank=True)
repliedat = models.DateTimeField(("replied at"), null=True, blank=True)
senderarchived = models.BooleanField(("archived by sender"), default=False)
recipientarchived = models.BooleanField(("archived by recipient"), default=False)
sender_deletedat = models.DateTimeField(("deleted by sender at"), null=True, blank=True)
recipient_deletedat = models.DateTimeField(("deleted by recipient at"), null=True, blank=True)
class MessageSerializer(ModelSerializer):
class Meta:
model = 'postman.Message'
publish_fields = ['sender', 'subject', 'body']
from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter
from .serializers import MessageSerializer
from .models import Message
from django.contrib.auth.models import User
class MessageRouter(ModelRouter):
serializer_class = MessageSerializer
model = Message
route_name = 'message-router'
This is not working and I am unable to understand the basic of how swampdragon works and how i should pass the current user to the router to filter the queryset. Kindly help me to figure it out and to implement it correctly.
Hi, I am django postman for user to user messaging. I want to push notification to user when a new message is received. I am using angular in front end. I tried the following:
models.py
class Message(SelfPublishModel, models.Model): SUBJECT_MAX_LENGTH = 120 serializerclass = MessageSerializer subject = models.CharField(("subject"), max_length=SUBJECT_MAXLENGTH) body = models.TextField(("body"), blank=True) sender = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='sent_messages', null=True, blank=True, verbosename=("sender")) recipient = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='received_messages', null=True, blank=True, verbosename=("recipient")) email = models.EmailField(_("visitor"), blank=True) # instead of either sender or recipient, for an AnonymousUser parent = models.ForeignKey('self', related_name='next_messages', null=True, blank=True, verbosename=("parent message")) thread = models.ForeignKey('self', related_name='child_messages', null=True, blank=True, verbosename=("root message")) sentat = models.DateTimeField(("sent at"), default=now) readat = models.DateTimeField(("read at"), null=True, blank=True) repliedat = models.DateTimeField(("replied at"), null=True, blank=True) senderarchived = models.BooleanField(("archived by sender"), default=False) recipientarchived = models.BooleanField(("archived by recipient"), default=False) sender_deletedat = models.DateTimeField(("deleted by sender at"), null=True, blank=True) recipient_deletedat = models.DateTimeField(("deleted by recipient at"), null=True, blank=True)
moderation fields
serializers.py
class MessageSerializer(ModelSerializer): class Meta: model = 'postman.Message' publish_fields = ['sender', 'subject', 'body']
from swampdragon import route_handler from swampdragon.route_handler import ModelRouter from .serializers import MessageSerializer from .models import Message from django.contrib.auth.models import User
class MessageRouter(ModelRouter): serializer_class = MessageSerializer model = Message route_name = 'message-router'
route_handler.register(MessageRouter)
controller.js
var MessageControllers = angular.module('MessageControllers', []);
MessageControllers.controller('MsgCtrl', ['$scope', '$dragon', function ($scope, $dragon) { $scope.msgs = {}; $scope.channel = 'messages';
}]);
In the template I am printing {{ msg.body }}
This is not working and I am unable to understand the basic of how swampdragon works and how i should pass the current user to the router to filter the queryset. Kindly help me to figure it out and to implement it correctly.
Regards Andy