1

カテゴリのすべての子を取得しようとしています:

def list_sub(self, category_name):
   # this will return the parent if exists
   category = Category.objects.filter(seo_title__exact = seo_title).filter(lang__exact = 'pt-PT').filter(level__exact = 1)

   if category:
      # but this doesn't work and in the documentation there are no examples
      # of how to get it. See link about the method
      sub_categories = category.get_children()

http://django-mptt.github.com/django-mptt/models.html#get-children

アップデート1:

qc = Category.objects.filter(seo_title__exact = cat).filter(lang__exact = 'pt-PT').filter(level__exact = 1)
category = qc.get()

if category:
    qsc = category.get_children()
    sub_categories = qsc.get()

「get() が複数のカテゴリを返しました -- 7 が返されました!ルックアップ パラメータは {} でした」というエラーが表示されるようになりました。

ありがとう

4

1 に答える 1

6

あなたの問題は MPTT にはありません。問題はcategory、インスタンスではなくクエリセットでget_children()あり、クエリセットメソッドではなくモデルメソッドであることです。

getの代わりに使用しfilterます。

于 2011-11-08T09:58:15.793 に答える