Tabela łączone wiersze django template

Tabela łączone wiersze django template
SU
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 15
0
Kopiuj
<div class="container">
<table class="table">
<tbody>
{% for obj in object_list %}
    {% with length_ as obj.teacher_set.all|length %}
    {% for teacher  in obj.teacher_set.all %}
	<tr>
<td {% if length_ > 1 %} rowspan={{length_|sub:"{{forloop.counter}}"}} {%endif%} > {{obj}}</td>
	 <td> {{teacher.first_name}} {{teacher.surname}} </td>
        </tr>
{% endwith %}
{% endfor %}
	{% endfor %}
	</tbody>
	</table>

Otrzymuję taki błąd
sub requires 2 arguments, 1 provided
A chcę uzyskać coś takiego:
screenshot-20200920164644.png

masochista
  • Rejestracja: dni
  • Ostatnio: dni
  • Lokalizacja: Warszawa
  • Postów: 77
0

Stack trace mówi "sub requires 2 arguments, 1 provided". Próbowałeś przeinstalować windowsa? ;)

SU
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 15
0

wywalenie length_ i pewne dobre zmiany pomogły

Kopiuj
<table class="table">
<tbody>
{% for obj in object_list %}
<tr> {% if obj.teacher_set.all|length > 0 %}
<td {% if obj.teacher_set.all|length > 1 %} rowspan={{obj.teacher_set.all|length}} {%endif%} > {{obj}}</td>
{% endif %}
{% for teacher in obj.teacher_set.all %}
 <td> {{teacher.first_name}} {{teacher.surname}} </td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.