I would like to override default Admin Panel result list (change_list_results.html) to add ID for each row in <tr>
Default is:
<tbody>
{% for result in results %}
{% if result.form.non_field_errors %}
<tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
{% endfor %}
</tbody>
I would like to have:
<tbody>
{% for result in results %}
{% if result.form.non_field_errors %}
<tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %}" id="{{ ID }}">{% for item in result %}{{ item }}{% endfor %}</tr>
{% endfor %}
</tbody>
What should i put into {{ ID }} to get element ID?
Unfortunately, the ‘items’ context variable does not hold instance data, it’s just a list with html for each column. To achieve what you need you must search for the equivalent item in the ‘cl.result_list’ context variable, based on the forloop counter:
Alternatively, if you don’t like all these ‘with’ tags you could create a custom template to get the item from “cl.result_list” directly from the counter index.