0

저는 Q를 건축 중입니다 & 토픽이 포함 된 포럼을 포함한 카테고리가있는 스타일 커뮤니티이며 각 토픽에 게시물이 있습니다. 방문 페이지에서 모든 카테고리에서 인기 주제를 원하고 카테고리 내에서 인기있는 주제를 해당 카테고리에서 원합니다. 템플릿 필터를 정의했지만 카테고리 나 집 수준에서는 아무 것도 표시하지 않습니다. 포럼 수준에서 일종의 작업을 수행 할 수 있습니다. 즉 특정 포럼 내부에서 해당 포럼의 모든 주제를 가져올 수 있습니다. 카테고리 안에는 현재 해당 카테고리의 각 포럼에서 모든 주제를 가져와야합니다. 현재는 모든 주제 목록이 아닌 해당 카테고리의 포럼 목록 만 반환합니다. 집 수준에서는 모든 카테고리에서 주제 목록을 반환하고 포럼을 포함하고 있지만 아무 것도 얻을 수 없습니다.모델 쿼리가 제대로 작동하지 않는 이유는 무엇입니까?

누군가 나에게 무슨 일이 일어나는지 알아낼 수 있습니까? 감사합니다

내 TOPICSFORALL.HTML :

{% block card_body %} 
{% for topic in topic_list %} 
    {% include "subjectcard.html" with topic=topic %} 
{% endfor %} 
{% endblock %} 

내 SUBJECTCARD.HTML :

{% block card_body %} 
{% for topic in topic_list %} 
    {% include "subjectcard.html" with topic=topic %} 
{% endfor %} 
{% endblock %} 

내 SITE_BASE.HTML :

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

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

... 
{% block body %} 
    <!-- Main hero unit for a primary marketing message or call to action --> 

    <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">{% include "categoryindex.html" %}</div> 
    <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">{% include "breadcrumbbt.html" %}</div> 

    {% if category %} 

    <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;">{% include "topicstyleforumindex.html" %}</div> 
    <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;">{% include "topicsforall.html" with topic_list=category|topicsbycat %}</div> 

    {% elif forum %} 

    <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;">{% include "topicindex.html" %}</div> 
    <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;">{% include "topicsforall.html" with topic_list=forum|topicsbyforum %}</div> 

    {% elif topic %} 
    <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%;">{% include 'pybb/topic.html' %}</div> 

    {% else %} 

    <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;">{% include "topicstyleforumindex.html" %}</div> 
    <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;">{% include "topicsforall.html" with topic_list=topicsbyallcatnforum %}</div> 

    {% endif %} 

{% endblock %} 

내 PYBB_TAGS.PY :

@register.assignment_tag 
def topicsbyall(): 
    topic_list = Topic.objects.all().order_by('-updated', '-created') 
    return topic_list 
,210

내 TOPICSBYFORUM.PY : 레지스터 = template.Library()

@ register.filter

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

내 TOPICSBYCAT.PY :

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 

답변

0

잘 모르겠어요 정확히 문제는하지만 템플릿 필터를 변경하여 각 쿼리 집합에서 수행하고 필터를 호출하는 동안 내 템플릿에서 루프를 더 많이 사용하여 작동하도록했습니다. 필터가이 영역에서 몇 가지 제약을받는다고 생각합니다. 나는이 문제를 분명히하고이 게시물을 업데이트하는 더 구체적인 포인트를 찾으려고 노력할 것입니다.하지만 그때까지는 저의 질문에 대답 해 준 6 명의 사람들에게 감사드립니다!

관련 문제