On Wed, Sep 17, 2008 at 3:11 PM, Dana <[EMAIL PROTECTED]> wrote:
[...]
> My issues is that I have used a context_processor to make the
> "Resources" that are related to the "Story" usable in the templates,
> but the context is being applied to all admin views (as is the nature
> of context_processors), which is causing an error (other than on the
> change_form.html page, which is working as expected). My question is
> how can I apply my context_processor to just the "Story" Change page
> and no where else? Should I use something other than a context
> processor? I know with views you can pass in a RequestContext but I am
> not sure how to do that without modifying the Django code. Im sure
> there is a simple fix and Id love if you could help me find it!

Using Django 1.0 this is quite easy actually. In the ModelAdmin of the
model you want to add the extra context data to you can simply
override the render_change_form method and add in your own context and
call the parent method.

class MyModelAdmin(admin.ModelAdmin):
    def render_change_form(self, request, context, **kwargs):
        context.update({
            "my_var": 1,
        })
        return super(MyModelAdmin, self).render_change_form(self,
request, context, **kwargs)


This will give you access to {{ my_var }} in only the change_form.html
template. Keep in mind this method is called for both the add and
change views. If you need to differentiate between the two you can put
a conditional around kwargs["add"] and/or kwargs["change"] which will
be True in their respective cases.

-- 
Brian Rosner
http://oebfare.com

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

Reply via email to