views:

38

answers:

1

I hope this hasn't been asked and I just missed it, but I searched a bunch and couldn't find anything.

I'm adding an extra save button to the django admin when adding or changing an object. Doing that is fairly easy. I just overrode the submit_line.html to add the extra button and then overrode the save_model function to check for the name of that button. It works great.

My problem is that I only need this button to appear for one particular object... not all of them. I looked in change_form.html to see how it knows what object it is dealing with and found {{ opts.module_name }}, but it doesn't seem to be accessible in submit_line.html. I tried printing it out and nothing showed up.

I also thought about hacking save_as (not very graceful, but I don't really care for this particular project), but that button only shows up on change.. not on add, so that won't work.

Does anyone know how to detect what object I'm working with in submit_line.html? Or any other way of doing this?

Thanks!

A: 

You should be able to access the original object in change_view's context through original. For example {{ original.id }} should print its id!

lazerscience
Do I need to do anything to get that to work? I put {{ original.id }} before the submit buttons and nothing is showing up. (I add some plain text right after it too to make sure the changes were showing up.)
lovefaithswing
Sorry just saw that the submit line is rendered through a template tag, so you cant access original there. You would neet to make your own template tag to pass the parameters you desire to the template, see http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templatetags/admin_modify.py#L22 for the original one!
lazerscience