我有这个request_control.html:
<form method="post" action="{% url 'cost_control_app:request_update' form_request_update.instance.request %}">
{% csrf_token %}
<div class="row">
{%include "partials/field.html" with field=form_request_update.request %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.request_date %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.request_type %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.request_description %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.user_login %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.state %}<br clear="all"/>
{%include "partials/field.html" with field=form_request_update.closed_date %}<br clear="all"/>
</div>
{% for group in user.groups.all %}
{% if group.name == 'IC Admins' %}
<input type="submit" class="btn btn-primary" value="Atender"/>
{% endif %}
{% endfor %}
</form>
我需要将其中一些字段设置为readonly,我该怎么办?
感谢您的帮助!!
答案 0 :(得分:0)
搞定了!!
首先,我必须在模板中调用此行,以便识别小部件调整:
{% load widget_tweaks %}
然后调用include中的属性,如下所示:
{%include "partials/field.html" with field=form_request_update.request|attr:"readonly:True" %}
像魅力一样。