如果员工关闭,我正试图在某个字段中隐藏评论。我已将if标记添加到字段本身,但在ifchange
循环中,如果员工已启用,则不会看到更改并在字段中添加注释。我将其移到ifchange
之上,但如果员工关闭则不会显示任何字段。所以基本上我的检查会跳过第一个(非工作时间)但是if_changed会忽略第二个,因为bar_record是相同的。我无法弄清楚如何工作。非常感谢任何帮助!
更新
我通过将if not foo.is_off
移到DOM上来解决这个问题,但我被告知这可能会更短。那是if
。
CODE
{% for foo in bar_information.bar_hours %}
{% if not foo.is_off %} <!-- is there a shorter better way of writing this? -->
{% ifchanged foo.bar_record %}
<tr class="{% cycle 'rowEven' 'rowOdd' %}">
<td>
{{ foo.bar_record.get_formatted_id }}
</td>
<td>
{{ foo.bar_record.entered_in|date:"DATETIME_FORMAT" }}
</td>
<td>
{{ foo.bar_record.get_display }}
</td>
<td>
{{ foo.bar_record.get_mistake_display }}
</td>
<td>
{% if foo.bar_record.number_shifts %}
{{ foo.bar_record.number_shifts }}
{% endif %}
</td>
<td>
<div style="width: 400px; word-wrap: break-word;">
{{ foo.bar_record.comments }} <!-- THIS COMMENT IS WHAT I NEED TO HIDE IF EMPLOYEE IS OFF -->
</div>
</td>
<td align="right">
<a class="button"
href="{% url 'bar_record_view' foo.bar_record.pk %}">
View Record</a>
{% has_permission_cust CHECK_COMPLIANCE %}
{% url 'check_compliance' foo.bar_record.pk as check_compliance_url %}
<a href="{{ check_compliance_url }}" class="button">Check Compliance</a>
{% end_has_permission_cust %}
</td>
</tr>
{% endifchanged %}
{% endif %}
{% empty %}
{% endfor %}
答案 0 :(得分:0)
我发现将'if not foo.is_off'移动到它工作的DOM上。就这样:
{% for foo in bar_information.bar_hours %}
{% if not foo.is_off %} <!-- is there a shorter better way of writing this? -->
{% ifchanged foo.bar_record %}
<tr class="{% cycle 'rowEven' 'rowOdd' %}">
<td>
{{ foo.bar_record.get_formatted_id }}
</td>
<td>
{{ foo.bar_record.entered_in|date:"DATETIME_FORMAT" }}
</td>
<td>
{{ foo.bar_record.get_display }}
</td>
<td>
{{ foo.bar_record.get_mistake_display }}
</td>
<td>
{% if foo.bar_record.number_shifts %}
{{ foo.bar_record.number_shifts }}
{% endif %}
</td>
<td>
<div style="width: 400px; word-wrap: break-word;">
{{ foo.bar_record.comments }} <!-- THIS COMMENT IS WHAT I NEED TO HIDE IF EMPLOYEE IS OFF -->
</div>
</td>
<td align="right">
<a class="button"
href="{% url 'bar_record_view' foo.bar_record.pk %}">
View Record</a>
{% has_permission_cust CHECK_COMPLIANCE %}
{% url 'check_compliance' foo.bar_record.pk as check_compliance_url %}
<a href="{{ check_compliance_url }}" class="button">Check Compliance</a>
{% end_has_permission_cust %}
</td>
</tr>
{% endifchanged %}
{% endif %}
{% empty %}
{% endfor %}