You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a class-based view (ListView) and have code that is structured as follows in the template. The permission check is returning false when I would expect the delete_widget permission to be present in the widget_perms for objects in the collection for the logged-in user. Am I using get_obj_perms incorrectly within a looping structure? If so, might an example of how to use it correctly when looping over an object list in a template be added to the docs?
{% load guardian_tags %}
{% block content %}
{% if object_list %}
{for widget in object_list %}
{% get_obj_perms request.user for widget as "widget_perms" %}
{% if "delete_widget" in "widget_perms" %}
<a href="/widget/delete/{{ widget.pk }}" class="btn btn-danger" role = "button">Delete</a>
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
Thanks!
K
The text was updated successfully, but these errors were encountered:
Thank you! I hadn't realized that prefetch_perms support had been added to guardian_tags for use in templates (I was going by the docs and thought only get_obj_perms was available). I'll give it a shot tonight.
It looks like prefetch_perms isn't (yet) supported in guardian_tags. I just went with a less elegant approach- adding a deletable_widgets collection to the context with a get_context_data override on the (class-based) view, then in the template
{% if widget in deletable_widgets %}
<a href="/widget/delete/{{ widget.pk }}" class="btn btn-danger" role = "button">Delete</a>
{% endif %}
I am using a class-based view (ListView) and have code that is structured as follows in the template. The permission check is returning false when I would expect the delete_widget permission to be present in the widget_perms for objects in the collection for the logged-in user. Am I using get_obj_perms incorrectly within a looping structure? If so, might an example of how to use it correctly when looping over an object list in a template be added to the docs?
Thanks!
K
The text was updated successfully, but these errors were encountered: