Django MPTT - absolute url for category -


i have following tree structure:

cat 1 --sub cat 1 --sub cat 2 cat 2 --sub cat 1 --sub cat 2 ----subsub cat 1 

using django-mptt i'm able display information using 1 query great, when trying create url like:

http://www.somesite.com/categories/cat1/subcat1/subsubcat1/ 

it doing sql lookup each of categories in tree parent nodes slug (which understandable.) here code:

@models.permalink     def get_absolute_url(self):         if not getattr(self, '_slug', none):             url = self.slug             ancestor in self.get_ancestors(ascending=true):                 url = url + ancestor.slug + u'/'             self._slug = url             return ('catalogue_category', [str(self._slug)]) 

is there functionality of mptt allow me create url slug without going crazy on sql?

i think answer question no. daniel points out in comment should able ancestors 1 query, agree eg. have list of categories need hit database each item once. if that's problem project think caching instance's slugs somewhere , update them on post_save signal of category model fit new slugs / titles!


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -