Python 使用Django一次更新多个记录

Python 使用Django一次更新多个记录,python,django,database,django-templates,Python,Django,Database,Django Templates,我想知道一种方法,如何在从输入框编辑完数据后立即更新数据,只需单击一下。我发现了这篇关于如何使用复选框的帖子: 但我不知道如何做输入框 这是我的密码: <table class="table table-striped table-bordered table-hover dataTables-example" > <thead> <tr> <th>Local</th>

我想知道一种方法,如何在从输入框编辑完数据后立即更新数据,只需单击一下。我发现了这篇关于如何使用复选框的帖子: 但我不知道如何做输入框

这是我的密码:

<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>
views.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')

你已经准备好表单了吗?我做了类似的事情,但是更新了每个字段,并且添加了一个类似的表单:对不起,我是指django表单,python代码来更新你的记录。让我编辑我的问题并添加forms.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')