adapt admin interface

2 views
Skip to first unread message

sveri

unread,
Aug 5, 2009, 3:36:08 PM8/5/09
to Django users
Hi,

i wonder if it is possible to change the admin interface of an app
like that:
Imagine i have a model:

class Entries(models.Model):
party = models.ForeignKey('party.Parties')
politician = models.ForeignKey('politician.Politicians')
name = ...

Now i go to the admin interface of Entries and want to add a new
Entry.
Then i select a party for the new entry.
After having that selected i want to reload the form ajax like
and show only the politicians that belong to that specific selected
party.

I hope i could express what i want good enough.

Thanks in Advance for any advices
Sven

Peter Herndon

unread,
Aug 5, 2009, 6:24:03 PM8/5/09
to django...@googlegroups.com
On 08/05/2009 03:36 PM, sveri wrote:
> Hi,
>
> i wonder if it is possible to change the admin interface of an app
> like that:
>
Yes, it is very possible.

> Now i go to the admin interface of Entries and want to add a new
> Entry.
> Then i select a party for the new entry.
> After having that selected i want to reload the form ajax like
> and show only the politicians that belong to that specific selected
> party.
>

One way to do this would be to override the admin template for the
change_form.html for your model, and add the necessary Javascript to it
to do what you need. You will likely need to create a view for your app
that performs the querying for your Ajax request, but you'd write the
view like you would any other, and you'd just override the admin
template to include the Javascript that calls to your view and parses
the response.

Overriding the admin templates documentation is here:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

Hope that helps,

---Peter

Reply all
Reply to author
Forward
0 new messages