Sorry for noob question.
Assuming we have a model with relation:
class Book(models.Model):
name = models.CharField(max_length=300)
category = models.ForeignKey(Category)
class Category(models.Model):
name = models.CharField(max_length=300)
Is it possible to somehow group results so in the template we can have something like this?
<ul>
{% for category in book_categories%}
<li>
{{category.name}}
<br/>
{% for book in category%}
{{book.name}} , {{book.author}}, etc...
{% endfor %}
</li>
{% endfor %}
</ul>
or am I making things complicated and there is an easier way to achieve html output like that?
Pass the categories to your template, and then you can do something like this