Message from discussion
How to overwrite the hyperlink of objects in change list template of django admin?
MIME-Version: 1.0
Message-ID: <d35b1bf1-d60f-4d5f-89bc-0deb6dabc43c@q10g2000prf.googlegroups.com>
Date: Mon, 14 Apr 2008 04:04:01 -0700 (PDT)
Received: by 10.142.14.20 with SMTP id 20mr21173wfn.10.1208171041682; Mon, 14
Apr 2008 04:04:01 -0700 (PDT)
In-Reply-To: <1208136189.27246.3.camel@counterweight.tredinnick.org>
X-IP: 207.46.92.19
References: <3ca3f9dd-63c0-417c-82ad-7bd290114083@t12g2000prg.googlegroups.com>
<1208136189.27246.3.camel@counterweight.tredinnick.org>
User-Agent: G2/1.0
X-HTTP-Via: 1.1 JPN-PRXY-09
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.13)
Gecko/20080311 Firefox/2.0.0.13,gzip(gfe),gzip(gfe)
Subject: Re: How to overwrite the hyperlink of objects in change list template
of django admin?
From: Leon <LeonChen8...@gmail.com>
To: Django users <django-users@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I've tried that method and make my own object list in the customized
change_list.html.
That REALLY duplicate a lot of works. Is it possible to add a hook
function (middleware?) just
before the change_list template being rendered? In that way, I might
be able to modify the
data before it is passed to template.
I had expected there is a magic function in model class to change it. :
(
On Apr 14, 9:23 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Sun, 2008-04-13 at 06:20 -0700, Leon wrote:
> > Hi,
> > I use django admin to manage a table. There is a hyperlink for
> > each object in the change_list template, which will bring me to the
> > change_form template. I want to change that hyperlink and redirect it
> > to another url to handle. I didn't want to customize the current
> > change_form for this model because it is still used somewhere else.
> > Anybody knows how to do it?
>
> It's possible, but fairly fiddly. You can create a custom
> change_list.html template for just that application + model name
> combination (since the admin interface tries to load a template under
> admin/<app_name>/<model_name>/change_list.html as one of the options for
> that page). Then you need to write a template that displays what you
> would like, which possibly means duplicating a lot of the logic of the
> original page and the template tags that construct it. With a bit of
> tracing through the code (admin/templates/admin/change_list.html,
> admin/tempates/admin/change_list_result.html,
> admin/templatetags/admin_list.py, admin/views/main.py) it should be
> quite possible to achieve what you want. Take your time and you'll get
> there (or use newforms-admin or wait for newforms-admin to be merged
> into trunk, both of which will be easier).
>
> Note that this sort of customisation does require you to read some
> Python code and templates and do a bit of design work. There isn't a
> step-by-step guide, so if you aren't up to being able to read the code a
> bit, this probably isn't the right sort of customisation to be trying to
> make.
>
> Regards,
> Malcolm
>
> --