こんにちは、テンプレート内のカスタムユーザnit要求ユーザのパーマを確認する方法はありますか。 コード例:テンプレートのユーザ権限を確認してください(ユーザはリクエストしないでください)
{% for agency_user in users %}
<tr>
<td>{{ agency_user.username }}</td>
<td>{{ agency_user.get_full_name }}</td>
<td>{{ agency_user.groups.all.first.name }}</td>
<td>{{ agency_user.min_price }}</td>
<td>{{ agency_user.max_price }}</td>
{% if agency_user|has_perm:'may_see_commerce_sell' %} #not working
<td>some action</td>
{% else %}
<td>some action</td>
{% endif %}
<td>
<a href="{% url 'user_edit' agency_user.id %}" class="edit icon"></a>
<a user-id="{{ agency_user.id }}" class="trash icon" title="some action"></a>
</td>
</tr>
{% empty %}
<td style="text-align: center" colspan="11">some action</td>
{% endfor %}
または私は、各ユーザーの権限にカスタムモデルメソッドを書くことがありますか? Profileモデルで考えるよう
何か:
def sell_commerce(self):
if self.has_perm('may_see_commerce_sell'):
return True
else:
return False
としてそれを使用しますタグライブラリ。 – Beliaf
'templatetags'ディレクトリは、インストールされているアプリの中になければなりません。 – Alasdair
これはアカウント(アプリ)/ templatetags / – Beliaf