Customizable object tools

94 views
Skip to first unread message

ao

unread,
Dec 19, 2006, 9:36:00 AM12/19/06
to Django developers
Hi,

At least a couple of times I needed to add additional links in a
changelist page (like "Add Item+"). So I tweaked admin code to accept
"object_tool_links" attribute in model's Admin class where I specify a
3-tuple (link_text, link_href, classes) eg.
('Clean Up', 'cleanup/', 'customlink someotherclass')
Of course now every time I svn update it goes away, so I was thinking I
ask here first if it was worth submitting a ticket+patch.

Cheers,
Andrius

Gary Wilson

unread,
Dec 19, 2006, 12:09:20 PM12/19/06
to Django developers
FYI, I filed a ticket [1] about this same topic last week, but I was
asking for an extra block tag in the change_list template. I am
assuming that you are also putting the object_tool_links on the
change_list page?

Looking at my ticket again, I am thinking it would be better to put the
block tag in the admin/base_site.html template, that way any other page
extending admin/base_site.html could add custom object tools instead of
just the change_list page.

As for your suggestion, what if you wanted to put object tools on the
change_form page too? It's starts to get messy with adding Admin class
attributes for each of the pages. Probably more elegantly handled in
the templates.

[1] http://code.djangoproject.com/ticket/3128

Gary Wilson

unread,
Dec 19, 2006, 11:39:25 PM12/19/06
to Django developers
Gary Wilson wrote:
> Looking at my ticket again, I am thinking it would be better to put the
> block tag in the admin/base_site.html template, that way any other page
> extending admin/base_site.html could add custom object tools instead of
> just the change_list page.

I meant admin/base.html. Added new and improved patch to ticket.

http://code.djangoproject.com/ticket/3128

ao

unread,
Dec 20, 2006, 6:07:11 AM12/20/06
to Django developers
I saw your ticket got patched and changed my code to use templates for
extended object tools. Works great but still gets a bit messy when i
have to create new template file for each model I want to have one
extra link and then write code to load that custom
<model>_change_list.html instead of original one. If it somehow did the
same like with generic views where it looks for a <model>_detail.html
but loads a default detail.html if former does not exist.


On Dec 20, 6:39 am, "Gary Wilson" <gary.wil...@gmail.com> wrote:
> Gary Wilson wrote:
> > Looking at my ticket again, I am thinking it would be better to put the
> > block tag in the admin/base_site.html template, that way any other page
> > extending admin/base_site.html could add custom object tools instead of

> > just the change_list page.I meant admin/base.html. Added new and improved patch to ticket.
>
> http://code.djangoproject.com/ticket/3128

Ville Säävuori

unread,
Dec 20, 2006, 6:54:24 AM12/20/06
to Django developers
ao wrote:

> <model>_change_list.html instead of original one. If it somehow did the
> same like with generic views where it looks for a <model>_detail.html
> but loads a default detail.html if former does not exist.

+1 from me.

This would be great. But I think it would be better to name the
templates <app>_<model>_foo.html. It would make the customization of
admin pages very easy and Django-like.

Ville Säävuori

unread,
Dec 20, 2006, 7:30:01 AM12/20/06
to Django developers
Replying to myself

> This would be great. But I think it would be better to name the
> templates <app>_<model>_foo.html. It would make the customization of
> admin pages very easy and Django-like.

D'oh. After looking the admin source code, this allready works! I
wonder howcome it isn't documented? (Or is it?)

Anyway, you can override the default admin template (at least for
change_list.html and change_form.html) by putting your own template to
/yourtemplates/admin/<appname>/ for app-wide override or to
/yourtemplates/admin/appname/modelname/ for model-wide override,
respectively.

This is great. And I really think it should be better documented! :)

Gary Wilson

unread,
Dec 21, 2006, 12:12:17 PM12/21/06
to Django developers
Reply all
Reply to author
Forward
0 new messages