How to display a menu only for users of a group in Django?

0

I'm doing a project with django and I have the following query in the admin of django I created the group "Volunteer", to which I gave permissions so you can manage dogs (create, modify, delete)

Well now in the template, I have a button that sends to where I administer the dogs, but I want that button, only can see the users who are part of the staff or if they are from the group "Volunteer" that I created:

At the moment I've only managed to get that button to show it to the users that are part of the staff, but I do not know how to do it so that the members of the "Volunteer" group appear.

How could I fix it ??? thank you very much

    
asked by Hector Jara 27.11.2018 в 18:41
source

1 answer

1

Use a variable in your view and pass it to your template:

def mi_vista(request):
    # Tu código
    es_voluntario = request.user.groups.filter(name='Voluntario').exists()
    return render(request, 'template.html', {
        # Tus otras variables del contexto
        'es_voluntario': es_voluntario
    })

Then in your template:

{% if request.user.is_staff or es_voluntario %}
    ...
{% endif %}
    
answered by 27.11.2018 / 22:21
source