[Django]-Django Reverse Query in Template

41πŸ‘

βœ…

To access blog entries (Related Manager): blog.entry_set.all

To do other actions if blog have no entries, you have the {% empty %} tag that is executed when the set is empty.

{% block content %}
     {% for blog in blog_list %}
          {{ blog.tagline }}
          {% for entry in blog.entry_set.all %}
              {{entry.name}}
          {% empty %}
             <!-- no entries -->
          {% endfor %}
     {% endfor %}
{% endblock %}
πŸ‘€manji

9πŸ‘

based on your code you could do the following.

{% block content %}
     {% for blog in blog_list %}
          {{ blog.tagline }}
          {% for entry in blog.entry_set.all %}
              {{entry.name}}
          {% endfor %}
     {% endfor %}
{% endblock %}
πŸ‘€JamesO

Leave a comment