1
我如何查詢:Django的MPTT - 基於URL段
Home
Things with Fur
Dog
Horse
Basket Ball Games
Twenty One
Horse
假設slug
每個爲title.lower().replace(' ', '-')
,我的網址是:
/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')
,因爲碰巧有一個類別與不同類別下的slu 012 horse
,但在同一級別。那麼,我該如何正確查詢我的horse
類別,而無需攀登鏈條並檢查每個關卡?
我很害怕:(但是我發現存儲一個簡單的完整路徑sha1會使它對於較大的站點來說更簡潔/更小的DB索引,謝謝Daniel。 – orokusaki