あなたの新しいコンボボックスのキーがデータベースに正しいキーを持っている限り、javascriptを使用して値を更新することは何も問題ありません。
最後のエントリを保存した後にこの関数を呼び出します。
function refreshLocal(){
$.get(window.location.href, '', function(html){
// change the id to the local combox's id
var serverLocalDropBox = $(html).find('#id_local');
if (serverLocalDropBox.length){
$('#id_local').replaceWith(serverLocalDropBox);
}
})
}
あなたはjavascriptのソリューションを使用したくない場合は、あなたがあるとしてフラグがちょうどフォームを検証し、返さないことを見れば、あなたはリフレッシュフラグで、サーバー側でフォームを投稿することができます。外部キーに新しいエントリがあるので、クエリーセットを自動的に更新して新しいエントリを追加します。
function serverRefreshLocal(){
var $form = $('#your_form_id');
$form.append('<input type="hidden" name="refresh" value="true" />');
// you can use ajax submit and ajax refresh here if you don't want to leave the page
$form.submit();
}
//サーバーサイドここで
def your_form_post_view(request):
if request.POST.get('refresh', 'false') == 'true':
# initial is the trick to save user input
your_form = YourForm(initial=request.POST)
context = {
'form': your_form,
}
return render(request, 'your_template.html', context)
# your view code goes here
http://stackoverflow.com/questions/7782479/django-reverse-engineering-the-admin-sites-add-foreign-key-buttonこちらをご覧ください。 –