我的应用程序中有一个内联表单集,用于添加和删除广告系列,但有一个“显示”字段,如果有 100 个已注册的显示,则很难注册 20 个内联。因此,我使用 jquery 创建了一个侧边栏,在其中选择扇区并显示下面的显示。这个想法是单击“添加”按钮(Adicionar)并创建一个内联显示,其中填充了“显示”字段。如何创建一个内联表单集,其中“显示”字段填充侧栏中的选定显示?
图片如何: http: //postimage.org/image/3qp6bq5f9/
在侧边栏中我有:
list.append('<ul><li><input class="list-display" type="hidden" value="'+d.pk+'"> '+d.fields['nome']+' | Janelas: '+d.fields['janelas']+'\
<a class="btn btn-mini" onclick="addInlineFormset('+d.pk+');" value="Adicionar"><i class="icon-plus-sign"></i> Adicionar</a></li></ul>');
“d.pk”是所选显示器的 id。
我仍在尝试创建此内联。我在 form.html 中添加了一个包含:
<div id="janela">
{% include "project/campanha/display_inline.html" %}
</div>
这是阿贾克斯:
function addJanela(id) {
var object_id = id;
var url = '/project/campanha/get_formInline/'+object_id+'/';
$.ajax({
type: 'get',
url: url,
success: function(formset){
var janela = $('#janela');
janela.append(formset);
return false;
},
});
}
我的意见.py:
def get_formInline(request, object_id):
display = Display.objects.get(pk=object_id)
status = Status.objects.filter(nome__exact='Vendido')
initial=[{'postais' : 45, 'status': status,'display': display,}]
JanelaFormSet = inlineformset_factory(Campanha, Janela, extra=1)
formset = JanelaFormSet(initial=initial)
return render_to_response('project/campanha/display_inline.html', {'formset': formset,}, context_instance=RequestContext(request))
但在提交时只保存最后一个内联。form.html的源代码:
<input type="hidden" name="janela_set-TOTAL_FORMS" value="1" id="id_janela_set-TOTAL_FORMS" /><input type="hidden" name="janela_set-INITIAL_FORMS" value="0" id="id_janela_set-INITIAL_FORMS" /><input type="hidden" name="janela_set-MAX_NUM_FORMS" id="id_janela_set-MAX_NUM_FORMS" />
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<input type="hidden" name="janela_set-0-id" id="id_janela_set-0-id" />
<tr>
<td>Postais: <input type="text" name="janela_set-0-postais" value="45" id="id_janela_set-0-postais" /></td>
<td>Status: <select name="janela_set-0-status" id="id_janela_set-0-status">
<option value="" selected="selected">---------</option>
<option value="2">Girando</option>
<option value="1">Vendido</option>
</select></td>
<td>Display: <select name="janela_set-0-display" id="id_janela_set-0-display">
<option value="" selected="selected">---------</option>
<option value="1">Shopping Point</option>
<option value="2">Restaurante</option>
<option value="3">Centro de Artes</option>
</select></td>
<td><input type="checkbox" name="janela_set-0-DELETE" id="id_janela_set-0-DELETE" /></td>
在图像打印中显示 3 个内联,但在源中仅显示 1 个内联。=/
有人可以帮忙吗?谢谢!