Tweaking global template rendering

Hi all,
I want all objects rendered directly in the html through the template engine to include a link to their “admin” page. I could of course to this by adding -

{%if user.is_superuser %}{{ obj.get_admin_url }} {% endif %}

to every place in every template that an object might get rendered. But that’s a pretty hefty change.

I can’t think of a good way to do this. Something like a “decorator” for template rendering. Any advice gratefully received.
PS Hi and belated congrats to Ken Whitesell - I enjoyed the DjangoChat episode.

Couple different options come to mind -

  1. You could create an “intermediate” “object” template in your extends (or include) chains.

The typical pattern I see in tutorials and such are two levels of template, a base template and a detail template. Depending upon how you build your pages, you could construct a third layer sitting between your detail template and the base. Your detail page can then extend the intermediate layer which extends your base template. That intermediate layer serves as a “wrapper” around your details.

  1. Change your base template to include this within another if to even determine if it’s appropriate to render it.

  2. The above ideas work only if you’re only rendering the detail for one object on your page. If you’re rendering multiple objects, you might want to look in a different direction - either a custom tag or a “child template” designed to be included by an object.

It’s still going to be a bit of work to include it, but it shouldn’t be that difficult.

(Thanks by the way - it was tremendous fun to do. Will and Carlton are great hosts.)