Snippet List
Two template tag filters that can be used to create a table from a sequence.
<table>
{% for row in object_list|groupby_columns:3 %}
<tr>
{% for obj in row %}
<td>{{ obj }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
The example above would create a table where items read from top to bottom, left to right, in 3 columns. "Empty" cells are added to the sequence by the filter so that your rows balance.
- filter
- templatetag
- table
- groupby
This takes the "easier to ask forgiveness than permission" approach to making sure your model's slug is unique.
If the model's slug is empty, make a slug from the model's 'name' field.
We assume that it is a conflicting slug that is throwing the IntegrityError, in which case if the slug does not end with '-' followed by a number then append '-2'. If the slug does end with '-' followed by a number then capture that final number, increment it by one, save the new slug value and try savin g again.
davidwtbuxton has posted 2 snippets.