Why isn't my Model Query set working properly?
<p>I'm building a Q&amp;A style community with categories containing forums which contain Topics and each topic has posts. On the landing page, I want popular Topics across all categories and when inside a category, I want all popular Topics within that category. I've defined template filters to do this but they aren't displaying anything at the category or home levels. They kind of work at the forum level i.e., inside a particular forum it is able to fetch all the topics in that forum. Inside a category, it is supposed to fetch all Topics from each of the forum in that category, currently, it just returns a list of the forums in that category rather than the list of all topics. At the home level, it is supposed to return a list of topics across all categories and contained forums but I get nothing.</p>

<p>Can someone please help me figure out whats happening here:? Thanks</p>

<p>My TOPICSFORALL.HTML:</p>

<pre><code>{% block card_body %}
{% for topic in topic_list %}
    {% include "subjectcard.html" with topic=topic %}
{% endfor %}
{% endblock %}
</code></pre>

<p>My SUBJECTCARD.HTML:</p>

<pre><code>{% block card_body %}
{% for topic in topic_list %}
    {% include "subjectcard.html" with topic=topic %}
{% endfor %}
{% endblock %}
</code></pre>

<p>My SITE_BASE.HTML:</p>

<pre><code>{% extends "theme_bootstrap/base.html" %}
{% load i18n pybb_tags topicsbycat topicsbyforum %}
{% load static %}

{% catindexlist as catindexlisted %}
{% topicsbyall as topicsbyallcatnforum %}

...
{% block body %}
    &lt;!-- Main hero unit for a primary marketing message or call to action --&gt;

    &lt;div class="col-xs-2 col-sm-3 col-md-2 col-lg-2" style="border-right:solid;text-align:right;height:99%;padding:0 0 0 0px;" id="sidebar"&gt;{% include "categoryindex.html" %}&lt;/div&gt;
    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" id="homebread"&gt;{% include "breadcrumbbt.html" %}&lt;/div&gt;

    {% if category %}

    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicstyleforumindex.html" %}&lt;/div&gt;
    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicsforall.html" with topic_list=category|topicsbycat %}&lt;/div&gt;

    {% elif forum %}

    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicindex.html" %}&lt;/div&gt;
    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicsforall.html" with topic_list=forum|topicsbyforum %}&lt;/div&gt;

    {% elif topic %}
    &lt;div class="main-block col-xs-6 col-xs-offset-1 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-2 col-lg-6 col-lg-offset-2" id="content" style="height:80%;"&gt;{% include 'pybb/topic.html' %}&lt;/div&gt;

    {% else %}

    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicstyleforumindex.html" %}&lt;/div&gt;
    &lt;div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-3 col-md-10 col-md-offset-2 col-lg-10 col-lg-offset-2" style="height:auto;padding-bottom:10px;text-align:center;"&gt;{% include "topicsforall.html" with topic_list=topicsbyallcatnforum %}&lt;/div&gt;

    {% endif %}

{% endblock %}
</code></pre>

<p>My PYBB_TAGS.PY:</p>

<pre><code>@register.assignment_tag
def topicsbyall():
    topic_list = Topic.objects.all().order_by('-updated', '-created')
    return topic_list
</code></pre>

<p>My TOPICSBYFORUM.PY:
register = template.Library()</p>

<p>@register.filter</p>

<pre><code>def topicsbyforum(forum):
    topic_list = Topic.objects.filter(forum=forum).order_by('post_count','views','-updated')
    return topic_list
</code></pre>

<p>My TOPICSBYCAT.PY:</p>

<pre><code>register = template.Library()

@register.filter
def topicsbycat(category):
    topic_list = []
    catforum = Forum.objects.filter(category=category).order_by('topic_count','post_count')
    for forum in catforum:
        forumtopics = Topic.objects.filter(forum=forum).order_by('post_count','views','-updated')
        topic_list.append(forumtopics)
    return topic_list
</code></pre>

<p>I'm not sure what exactly the issue was but I kinda got it to work by changing the template filters to do just on queryset each and using more for loops in my templates while calling the filters. I guess filters have some constraints in this area. I'll try finding more specific points that will clarify this issue and update this post but until then, thanks to the 6 people who tried answering my question!</p>

python django django-models django-templates django-template-filters