views:

197

answers:

1

for django.contrib.auth.User and django.contrib.auth.Group

i am doing like this

    for g in request.user.groups:
        l.append(g.name)

Got an error

TypeError at / 'ManyRelatedManager' object is not iterable Request Method: GET Request URL: http://localhost:8000/ Exception Type: TypeError Exception Value:
'ManyRelatedManager' object is not iterable Exception Location: C:\p4\projects...\users.py in permission, line 55

thanks for any help!

+2  A: 
for g in request.user.groups.all():
    l.append(g.name)

or with recent django

l = request.user.groups.values_list('name',flat=True)
MattH
works like a charm!
xlione