0
I followed the explanations of a page to create a group and add users to the group.
But now I want to list the users contained in the group and show in html
html tried some variations but no return the group users
{% for use in user.groups.all%}
{{use}}
{% endfor %}
{{user.groups.all}} retorna <QuerySet []>
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
grupo, created = Group.objects.get_or_create(name ='grupo1')
ct = ContentType.objects.get_for_model(User)
permissao = Permission.objects.create(codename ='can_go_haridwar',
name ='Can go to Haridwar',
content_type = ct)
grupo.permissions.add(permissao)
In the final code above, you are adding a permission to the group, not the user. For that, you could do something like
user.groups.add(grupo)
, this way would be persisted in the bank and any of those codes in the template would work– mazulo