私は持っている:
Home
Things with Fur
Dog
Horse
Basket Ball Games
Twenty One
Horse
slug
for each がであると仮定するとtitle.lower().replace(' ', '-')
、私の URL は次のようになります。
/home/
/home/things-with-fur/
/home/things-with-fur/dog/
/home/things-with-fur/horse/
/home/basket-ball-games/
/home/basket-ball-games/twenty-one/
/home/basket-ball-games/horse/
slug
フィールドunique_together
にはparent
.
URL セグメントに基づいて、正しいカテゴリを照会する必要があります。horse
でバスケットボールの試合を単純にクエリすることはできませんCategory.objects.get(mptt_level=2, slug=u'horse')
。たまたまhorse
別のカテゴリの下にスラッグがあるカテゴリがあるためですが、同じレベルにあります。horse
では、チェーンを上って各レベルをチェックすることなく、自分のカテゴリを正しくクエリするにはどうすればよいでしょうか?