Django Groups In Templates

4,071 views
Skip to first unread message

Dave Merwin

unread,
Jan 10, 2010, 3:12:32 AM1/10/10
to Django users
I'm trying to do something I thought was simple.

{% ifequal user.groups "subscribed" %}
Hello
{% endifequal %}

But it's not working...

Any tips?

G B Smith

unread,
Jan 10, 2010, 3:19:09 AM1/10/10
to Django users
user.groups.all returns not one but (possibly) many objects. Thus you
will have to do something like

{% for group in user.groups.all %}
{% if group.name == 'subscribed' %}
Hello
{% endif %}
{% endfor %}

Regards,
GBS

Dave Merwin

unread,
Jan 10, 2010, 3:21:53 AM1/10/10
to Django users
Brilliant!! That worked. Thanks.

G B Smith

unread,
Jan 10, 2010, 4:47:21 AM1/10/10
to Django users
If your users can belong to only one group, then check this out: -
http://stackoverflow.com/questions/1889607/django-middleware-to-determine-users-group-in-a-session

GBS.

Reply all
Reply to author
Forward
0 new messages