Re: message_set filter
so what's the question?
On Sat, Aug 17, 2013 at 7:52 AM, Karl Arunachal <kakararunachalservice@gmail.com> wrote:
--Hello,I have a model for messaging between the users.models.py:
class Message(models.Model): description = models.TextField() date_added = models.DateTimeField(default=datetime.now) sender = models.ForeignKey(User, related_name='sent_set') recipient = models.ForeignKey(User, related_name='recieved_set') def __unicode__(self): return "%s sent message: %s to %s" % (self.sender, self.description, self.recipient) def save(self, **kwargs): if self.sender == self.recipient: raise ValueError("Cannot message yourself") super(Message, self).save(**kwargs)
Suppose, msg has all the messages sent and recieved for user 'A'. Now how would i filter from this 'msg', all the message sent to and recieved from a particular user 'B'.
Till now I get all the messages (sent/recieved) of a particular user,from django.db.models import Q
A = request.user msg = Message.objects.filter(Q(sender=A)|Q(recipient=A))
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home