擅长:python、mysql、java
<p>试试这样。。。在</p>
<pre><code>all_data = []
all_topics = Topic.objects.all()
categorie_posts = Post.objects.filter(categorie=categories)
for each_topic in all_topics:
current_data = {}
current_posts = []
current_posts.append(categorie_posts.filter(Q(topic=each_topic))
# append more posts based on query here like Q(categorie__topic = each_topic) or something
current_data['topic']=each_topic
current_data['posts'] = current_posts
all_data.append(current_data)
</code></pre>
<p>现在在模板中</p>
^{pr2}$