Issue in Django count string in a template

37 views
Skip to first unread message

Ronaldo Bahia

unread,
Feb 12, 2015, 1:06:27 PM2/12/15
to django...@googlegroups.com

I am facing issues trying to get a count. Hope you can help me.

In the template, if I insert {{ message.count }} not happens 'coz message is a string. If I insert {% load inbox %} {% inbox_count as message %} it returns all unread messages, but I need to get the unread messages sent by a given user, in my case, a candidate to a job position.

How can I do it?

Here is the thread:
http://stackoverflow.com/questions/28484620/issue-in-django-count-string-in-a-template

Thanx,
Ronaldo

Bill Freeman

unread,
Feb 12, 2015, 2:00:28 PM2/12/15
to django-users
I presume that your messages are model instances.  If so, create a queryset for the unread messages in your view, and pass that, or the result of applying .count() to it, as a template context variable, say "unread_message_count".

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c9a6fd12-9c3a-4ac0-a2ed-550c1bb56e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ronaldo Bahia

unread,
Feb 12, 2015, 2:49:38 PM2/12/15
to django...@googlegroups.com
Thanks for answering.

Can you provide some example?

Cheers

Bill Freeman

unread,
Feb 12, 2015, 4:16:09 PM2/12/15
to django-users
Show me your view.

Reply all
Reply to author
Forward
0 new messages