Easy customizing of admin subsections?

Skip to first unread message

Jaanus

unread,
Dec 4, 2005, 4:22:16 AM12/4/05
to Django users
Hi,

Django is cool :-) Im currently looking at it to possibly use it in
several high-profile initiatives. So far so good.

One thing I came across is a question of whether I can easily customize
subsections of admin. Now the tutorials explain it nicely about
admin_base, but Id need to be more granular - lets say I have an app
for managing some assets, and one view of that app is downloading full
statistics in CSV format. Now I have created a view to output the CSV,
but Id like to link to it from the appropriate place in the admin. Lets
say in the view where I see all the objects of the app.

I took a look at admin.views.main and in change_list, I can see a lot
of hardcore fiddling with raw_template going on to produce the output.
Id avoid messing with that at all costs - rather, Id like to have parts
of the admin UI more templated so that I could customize the object
list view through the template and add my link at an appropriate
location. Does that sound reasonable? Or is there any other easy way
for me to accomplish this (insert custom link at an appropriate
location in the admin), other than messing with change_list code?

--
rgds,
Jaanus

Robert Wittams

unread,
Dec 4, 2005, 8:21:36 AM12/4/05
to django...@googlegroups.com
I think you want to upgrade to trunk, where a long term effort to make
the admin very customisable has been merged.

In your case, you will be able to create a template called:

admin/<my_app>/<my_model>/change_list.html

with

{%extends "admin/change_list.html"%}
{%block search%} <a href="/admin/csv_thing/">CSV
thing</a>{{block.super}}{%endblock%}

as the content.

Jaanus

unread,
Dec 4, 2005, 11:32:16 AM12/4/05
to Django users
Robert Wittams wrote:

> I think you want to upgrade to trunk, where a long term effort to make
> the admin very customisable has been merged.

Hey now... that was too easy! you're cheating! :D (I was indeed on .90
and trunk works as you say)

> In your case, you will be able to create a template called:
>
> admin/<my_app>/<my_model>/change_list.html
>
> with
>
> {%extends "admin/change_list.html"%}
> {%block search%} <a href="/admin/csv_thing/">CSV
> thing</a>{{block.super}}{%endblock%}
>
> as the content.

Yep, this worked, thanks, except that it was
admin/<my_model>/change_list.html (or my_app, dunno, name is the same,
anyway just one subdir needed, not one), and of course no .html
extension in "extends". Good stuff.

Robert Wittams

unread,
Dec 4, 2005, 7:36:47 PM12/4/05
to django...@googlegroups.com

> Yep, this worked, thanks, except that it was
> admin/<my_model>/change_list.html (or my_app, dunno, name is the same,
> anyway just one subdir needed, not one),

Both should work.

> and of course no .html
Doh! ;-)

tonemcd

unread,
Dec 9, 2005, 1:12:50 AM12/9/05
to Django users
Whoa, this is very neat...

I see the /admin/csv_thing/ URL getting dispatched to (presumably) a
method in the target app, <my_app> - is this correct?

If so (big drum roll here), does that mean a method in my_app can get
the content of 'result_list' from change_list.html, and work on it to
produce the CSV output? This would be a big deal IMHO.

And if so, how would the result_list get passed to the method?

Jaanus

unread,
Dec 11, 2005, 5:27:37 AM12/11/05
to Django users
> I see the /admin/csv_thing/ URL getting dispatched to (presumably) a
> method in the target app, <my_app> - is this correct?

Yes, I put it in the views of the app.

> If so (big drum roll here), does that mean a method in my_app can get
> the content of 'result_list' from change_list.html, and work on it to
> produce the CSV output? This would be a big deal IMHO.

Probably not. At least I didn't do it, I just got the data for the csv
generator using the standard get_list stuff etc, with Django it's only
a few lines anyway.


--
rgds,
Jaanus

Robert Wittams

unread,
Dec 11, 2005, 9:44:51 AM12/11/05
to django...@googlegroups.com

The best way to do this would be to override the view function in the
url conf, and subclass ChangeList. I don't claim that that class is
particularly well designed at the present time, so it might need a bit
of thought.

Reply all
Reply to author
Forward
0 new messages