tags:

views:

26

answers:

1

In an inline form, in the admin interface, I have a foreign key field.

If you look at the following image: http://www.image-share.com/ipng-147-172.html you will notice an engine field (Set to proximity).

What I'd like is to filter what appear in the list (currently track.context.max_media_duration and track.ambient.max_media_duration) bases on the engine selection.

I'd like it to change when the selection is changed, it will also have to mark existing one that has been filtered out for deletion or delete them.

I don't know where to start to implement such a feature.

Thanks

A: 

The easiest approach, in my opinion, would be to do it all as an AJAX callback (e.g. with jQuery). The general code flow might be the following:

  1. Add a jQuery onChange event to the id_engine field.
  2. When the id_engine pull down changes, it triggers a callback.
  3. That callback calls a URL you have set up back to a specific URL and returns values as JSON data.
  4. These values are what you use to overwrite what is found in the pull downs below... jQuery can overwrite these pretty simply. You just have to be careful to match what Django outputs by default -- keeping form names and values similar so Django will know how to handle it when POSTing the data back.
robhudson
I guess the full JS solution you proposed would be the best and also the simplest to implement, as I don't have a big dataset to filter (max a hundred). I'll wait for other proposition though.
I ended to implement that solution in a few lines of JS code and a simple django view.