1

我有:

Home
    Things with Fur
        Dog
        Horse
    Basket Ball Games
        Twenty One
        Horse

假设slugfor 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_togetherparent.

我需要根据 URL 段查询正确的类别。我不能简单地用 查询篮球比赛horseCategory.objects.get(mptt_level=2, slug=u'horse')因为恰好有一个类别与 slughorse在不同的类别下,但在同一级别。那么,我应该如何horse正确查询我的类别而无需爬上链条并检查每个级别?

4

1 回答 1

2

存储数据库中每个项目的完整路径。

于 2012-05-04T20:15:31.707 回答