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?
> 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?
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:
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.
> 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),
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?
> 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.
> 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?
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.