Filtering foreign keys with AJAX in Django admin

Posted by cnobile on Stack Overflow See other posts from Stack Overflow or by cnobile
Published on 2010-05-10T01:21:22Z Indexed on 2010/05/10 1:28 UTC
Read the original article Hit count: 246

Filed under:
|
|

I have most of this figured out already. I have AJAX returning the region/state/province when a country is selected. The correct foreign key is saved to the database, however, when the record is viewed afterwards the selected state is not shown in the select nor are any states for the selected country. I understand why this is happening as, the admin view is not aware of the relation between the state and the country.

So here is the question. Is there a hook in the admin view that will allow me to load the correct states for the country and set the selected attribute on the option in the select tag? Or how can I override the admin view for any forms that require the country and region/state/province set?

I am using jQuery and Djando-1.1.

Thanks

© Stack Overflow or respective owner

Related posts about django-admin

Related posts about foreign-key