开发者

How to filter an inlined foreign key based on master model

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 del开发者_运维技巧ete them.

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

Thanks


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜