In all my models I have a get_absolute_url()
method as the one below, but with django-debug-toolbar I see that it costs many SQL queries.
My objects are related in a tree structure, so a level 3 object only knows what level 1 object it is related to through level 2. How can I avoid these many SQL queries? Is it bad practice to relate objects through other objects? Do I have to save the level 1 slug and level 2 slug as CharFields
in my level 3 model?
@models.permalink
def get_absolute_url(self):
return ('url_alias', None, {'level1': self.level2.level1.slug, 'level2': self.level2.slug, 'level3': self.slug})