1

I have:

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

Assuming the slug for each is title.lower().replace(' ', '-'), my URLs would be:

/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/

The slug field is unique_together with the parent.

I need to, based on the URL segements, query for the correct category. I can't simply query for the basket ball game horse with Category.objects.get(mptt_level=2, slug=u'horse'), because there happens to be a category with the slug horse under a different category, but at the same level. So, how am I supposed to query for my horse category correctly without climbing up the chain and checking each level?

orokusaki
  • 55,146
  • 59
  • 179
  • 257

1 Answers1

2

Store the full path to each item in the database.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • I was dreading that :( but I found that storing a simple sha1 of the full path makes it a bit cleaner / smaller DB index for larger sites. Thanks, Daniel. – orokusaki May 04 '12 at 21:04