Monday, February 28, 2011

Re: Extend admin template without copying the whole template

There a ticket or two for this already. For example:
http://code.djangoproject.com/ticket/8158

(I think a workaround is to set your ModelAdmin's to use your own
template name and in they pull in and override elements of the base
templates. The only drawback is you are dependent on the built-in
templates having blocks where you need them.)

On Feb 28, 6:15 am, Martin <martin.brochh...@googlemail.com> wrote:
> Hi Alex,
>
> many thanks for your suggestion but I think {{ block.super }} will not help.
> In order to have a parent template I would first have to write something
> like {% extends "admin/base.html" %} but this already is not possible
> because it would mean inheriting itself.
>
> Best regards,
> Martin
>
>
>
>
>
>
>
> On Mon, Feb 28, 2011 at 1:41 PM, Alex Boyko <alex.kyr...@gmail.com> wrote:
> > On Monday, 28 February 2011, Martin Brochhaus
> > <martin.brochh...@googlemail.com> wrote:
> > > Hi all,
> > > I want to add a language switcher below the breadcrumb to all my django
> > admin pages.
> > > Therefore I created templates/admin/base.html in my project. However I
> > don't want to copy the whole original base.html and add my changes - this
> > would defeat the DRY principle and it would be a maintenance nightmare
> > whenever I update to the latest django version.
> > > So I tried the obvious:
> > > {% extends "admin/base.html" %}{% block breadcrumb %}[old breadcrumb
> > code][my additional code]{% endblock %}
> > > And of course the obvious error happened: The template tries to extend
> > itself. Couldn't the system be smart enough and recognize that it is trying
> > to import itself and then search for another template to extend at the next
> > available template loader in line? As in: Whoops, I'm trying to extend
> > myself when using base.html from the project's file system... ok let's see
> > if I can find admin/base.html in the python path or in the eggs...
> > > Is there any other fancy trick or workaround to accomplish this? I
> > believe that enhancing global admin templates should be something that is a
> > very common usecase, isn't it?
> > > Best regards,Martin
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > django-users+unsubscribe@googlegroups.com.
> > > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> > Hi, Martin!
>
> > If I got your point in right way - May be {{ block.super}}
> > construction will be useful for you.
>
> > Regards, Alex
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment