[Answer]-Unnecessary many SQL queries in Django

1👍

Are the slugs on your site permanent? If so, it is needless work to constantly calculate your URL like this. If your slugs are permanent, you could add a listener for saves on your model, and, at saving-time, populate a field with the URL to the object. Then your get_absolute_url could just show that.

If your slugs are not permanent, you could do as Matthew Daly suggested and store the URL-for-this-object in a cache bucket and check that. You’d still have to figure out how you wanted to clear that key (since it would need to change if you changed the slug for this object or any object higher up in the URL path).

Leave a comment