我想知道一种方法,如何更新数据一旦被编辑,从输入框都一键点击。我找到了一篇关于如何使用复选框的帖子: Updating several records at once using Django 但我不知道如何做输入框。你知道吗
这是我的密码:
<table class="table table-striped table-bordered table-hover dataTables-example" >
<thead>
<tr>
<th>Local</th>
<th>line</th>
<th>rack</th>
</tr>
</thead>
<tbody>
{% for linea in lineas_de_reporte %}
<tr>
<td>{{ linea.local }}</td>
<td><input type="text" name="case-opened" value="{{ linea.rack }}" id="caseOpened"/></td>
<td><input type="text" name="case-opened" value="{{ linea.line }}" id="caseOpened"/></td>
</tr>
{% endfor %}
</tbody>
有没有一种方法可以使用Django将所有值(按id)发送到列表中的函数?
编辑:
你知道吗表单.py你知道吗
class TVSForm(forms.Form):
rack = forms.CharField()
line = forms.CharField()
你知道吗视图.py你知道吗
def search_folio(request):
if request.method == 'POST':
form = FolioSearchForm(request.POST)
if form.is_valid():
folio_number = request.POST.get('folio_number', '')
folio = 'FOLIO' + str(folio_number)
folio_query = InventoryFolioManagement.objects.filter(folio=folio)
context = {
'lineas_de_reporte': folio_query,
'folio': ' | ' + folio
}
return render(request, 'inv-search-folio.html', context)
else:
form = FolioSearchForm()
if request.GET.get('rack'):
# ... this means that user clicked on the submit button
# get the id of linea
linea_id = request.GET.get('rack-id')
new_case = request.GET.get('rack')
# fetch object from db, based on that id (aka pk)
linea = TechnicalValidationSystem.objects.get(id=linea_id)
# change its attribute to True
linea.case_opened = new_case
# update db with the new value
linea.save(update_fields=['rack'])
return render(request, 'inv-search-folio.html')
目前没有回答
相关问题 更多 >
编程相关推荐