Equal row lengths in a table
I have a table made of of several records, with the rows having different 开发者_C百科number of records per row. What I'd like to have is for the rows with less records, I want to have them being equal in length to the longest row. Currently what I have comes out like below:
I've done this using this bit of code:
<table>
{% for week in month_days %}
{% for day, entries, weekday in week %}
<tr class="{% cycle 'row1' 'row2' %}">
{% if day != 0 %}
<td>{{ weekday }}</td>
<td>{{ day }}</td>
{% if entries %}
{% for entry in entries %}
<td>{{ entry.start_time|time:"h:i a" }}</td>
<td>{{ entry.end_time|time:"h:i a" }}</td>
<td>{{ entry.hours }}</td>
<td>Break</td>
{% endfor %}
{% endif %}
{% endif %}
</tr>
<!--- Insert blank row after each Sunday -->
{% if weekday == "Sunday" %}
<tr class="week-end">
<td colspan="{{ days_month.count }}"> </td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
From the above photo, as an example, I want, on the entry for Monday 16th, to have the blue space filled in with blank cells.
Try this:
{% if entries %}
{% for entry in entries %}
<td>{{ entry.start_time|time:"h:i a" }}</td>
<td>{{ entry.end_time|time:"h:i a" }}</td>
<td>{{ entry.hours }}</td>
<td>Break</td>
{% endfor %}
{% else %}
<td> </td>
<td> </td>
<td> </td>
{% endif %}
精彩评论