0

I need to get the username and the name of group for all user. The model that I use are User(default) and Group(default)

index.html:

{% for dato in usuarios %}
    {{dato.first_name|title}}
    {% for item in jefes %}
        {{dato.groups}}
    {% if dato.groups == item.id %} #I don't know to do this if
        {{item.name}}
    {% endif %}
    {% endfor %}
{% endfor %}

view:

def inicio(request):
    usuarios = User.Group.all()
    grupos = Group.objects.all()
    ctx = {'usuarios':usuarios,'grupos':grupos}
    return render_to_response('index.html', ctx, context_instance=RequestContext(request))
2
  • **** return render_to_response('index.html',ctx,context_instance=RequestContext(request))
    – Oztro
    May 19, 2013 at 3:34
  • What exactly is your question?
    – FDinoff
    May 19, 2013 at 3:52

1 Answer 1

1

You do not need the groups queryset from the view.

{% for dato in usuarios %}
    {{dato.first_name|title}}
    {% for group in dato.groups.all %}
        {{group.name}}
    {% endfor %}
{% endfor %}
1
  • im sorry, jefes = grupos, i forgot change it i need to show all users and your group name.
    – Oztro
    May 19, 2013 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.