Alex,

I set the related name to 'users'. I've printed out the field in the
template like this:

{{ message.users.all }}

It prints out something like:

[,,,,,,,,,,,,,]

So I know that it is working...

On Jul 13, 12:52 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> I`UserMessage` model has `users_read` field why do you write in
> template `message.users`?
>
> On Jul 13, 2:56 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
>
> > Hey,
>
> > I'm writing a messaging module at the moment. I'm printing out the
> > list of messages fine, but when I loop through each message I want to
> > check if the current user is in an array. This array has all of the
> > people who have read the message so far.
>
> > Model looks like this:
>
> > sender                  = models.ForeignKey(UserProfile)
> > date                    = models.DateTimeField(auto_now_add=True)
> > body                    = models.TextField()
> > users_read              = models.ManyToManyField(UserProfile,
> > related_name='users')
>
> > View looks like this:
>
> > thread_messages = UserMessage.objects.exclude(sender=user)
>
> > Template looks like this:
>
> > {% for message in thread_messages %}
>
> >         {% if user|IN:message.users.all %}
> >         Read
> >         {% else %}
> >         Unread
> >         {% endif %}
>
> > {% endfor %}
>
> > IN: template filter looks like this:
>
> > @register.filter
> > def IN(value,arg): return value in arg
>
> > All messages print Unread, even though half of them have the current
> > user added into the user_read field. Am I doing something majorly
> > wrong here?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to