Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue With Same Inbox Subject as Multiple Objects #104

Open
bobozar opened this issue Mar 8, 2018 · 4 comments
Open

Issue With Same Inbox Subject as Multiple Objects #104

bobozar opened this issue Mar 8, 2018 · 4 comments

Comments

@bobozar
Copy link

bobozar commented Mar 8, 2018

Messages in the inbox with the same subject keeps showing up more than once depending on the number of times a sender and the recipient receives messages. I want a situation whereby messages with the same subject will only show up once in the inbox and not twice or thrice. Kindly check the attached image for what I mean.

[url=https://ibb.co/b3AGQ7][img]https://thumb.ibb.co/b3AGQ7/Screenshot_35.png[/img][/url]

I've looked into the code and I did this

     message_list = Message.objects.inbox_for(request.user).values('subject').distinct()

But still not working.

@arneb
Copy link
Owner

arneb commented Mar 9, 2018

To show messages as threads, try to filter like this:

Message.objects.inbox_for(request.user).filter(parent_msg__isnull=True)

All messages where parent_msg is not null are replys in a thread.

You might need to replace the inbox_for filter with something like filter(Q(sender=user) || Q(recipient=user)) so that outgoing threads are also displayed.

@bobozar
Copy link
Author

bobozar commented Mar 9, 2018

@arneb, I tried this.. but it's not working fine. When I check my inbox [/messages/inbox] as the sender, no message will show up. But when I check as the receiver, I will see the message in my inbox and it won't show up multiple times. It's working for the receiver and not the sender.

What am I missing?

@arneb
Copy link
Owner

arneb commented Mar 9, 2018

did you replace the inbox_for filter with two or'ed Q queries?

with inbox_for it will only work for the receiver, because inbox_for does a receiver=user filter. you want receiver=user || sender=user

@bobozar
Copy link
Author

bobozar commented Mar 9, 2018

@arneb Thanks!

Now working. I did this.

messageo = Message.objects.filter(Q(sender=request.user) | Q(recipient=request.user)).filter(parent_msg__isnull=True)
So far, it's working fine.

Another issue I have is how to make 1. a message that has not been read and replied have the em tag. 2, message that has been replied and not read have the em tag. So I did this.

{% for mvg in messageo %}

     <p>
 	 {% if mvg.new %}
 	       <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>
             <strong> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </strong>
 			 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
 	
 	 {% elif mvg.replied_at is None %}		 
 	        <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>
             <em> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </em>
 			 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
 			
      {% elif mvg.replied_at %}
            {% if not mvg.read_at %}	
             <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>			   
             <em> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </em>
 			 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
 		   {% endif %}	   
      {% endif %}
 	</p>
{% endfor %}
 	

But not working! I'm on Django 1.11 . What am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants