I have the 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 to display this information using 1 query which is great, but when trying to create a url like:
http://www.somesite.com/categories/cat1/subcat1/subsubcat1/
It is doing a SQL lookup for each of the categories in my tree to get the parent nodes slug (which is understandable.) Here is my code:
@models.permalink
def get_absolute_url(self):
if not getattr(self, '_slug', None):
url = self.slug
for ancestor in self.get_ancestors(ascending=True):
url = url + ancestor.slug + u'/'
self._slug = url
return ('catalogue_category', [str(self._slug)])
Is there any functionality of MPTT that will allow me to create a url slug without going crazy on the SQL?