2010-12-12 3 views
3

こんにちは、私はMPTTを使って、会話を含むモデルからいくつかのツリー状のデータを作成しています。django-mpttが正しくデータをリンクしていない

このモデルは現時点では非常に基本的なものです。

class Thread(MPTTModel): 
    message = models.CharField(max_length=100) 
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children') 
    votes = models.IntegerField() 

    class MPTTMeta: 
     order_insertion_by=['votes'] 

ご覧のとおり、メッセージフィールドと、スレッドモデルにリンクされた親FKと、投票があります。私の意見の中で

私は私のテンプレートの中に、この

threads = Thread.tree.all() 
    data = { 
     'threads':threads 
    } 
    return render_to_response("show.html",data) 

を持って

{% load mptt_tags %} 

<ul class="root"> 
     {% recursetree d %} 
      <li> 
       {{ node.title }} 
       {% if not node.is_leaf_node %} 
        <ul class="children"> 
         {{ children }} 
        </ul> 
       {% endif %} 
      </li> 
     {% endrecursetree %} 
</ul> 

しかし、出力されたリストは、すべてのスレッドの一覧です。それらのどれも一緒にリンクされていません。

アイデア?

+0

これはあなたのアクチュアルコードですか?あなたの視点は、あなたの文脈で 'd'と呼ばれるものを埋め込んでいません... –

答えて

3
{% load mptt_tags %} 
<ul class="root"> 
    {% recursetree nodes %}    
     <li> 
      {{ node.message }} 
      {% if not node.is_leaf_node %} 
       <ul class="children"> 
        {{ children }} 
       </ul> 
      {% endif %} 
     </li> 
    {% endrecursetree %} 
</ul> 
私が持っているビューで

:HTMLページで

threads = Thread.tree.all() 
data = { 
    'nodes':threads 
} 
return render_to_response("show.html",data) 

私は、ノードの順アルファベット順とインデントとのツリーを参照してください。

関連する問題