Djangoテンプレートで手動でレンダリングされる次のフォームがあります。「手動でレンダリング」とは、対応するFormまたはModelFormオブジェクトがコードにないことを意味します(Formオブジェクトを使用しない理由/詳細は少し複雑であり、この質問から安全に除外できます)。私は今メンタルブロックを持っていますが、Djangoビュー内でこのデータを使用可能な形式で取得する方法を理解できないようです。具体的には、フォームがPOSTされたときに、それぞれattendance_value
とattendance_remarks
それぞれを取得するにはどうすればよいですか?workers_pks
<form>
<table>
<thead>
<tr>
<th>Sl</th>
<th>Worker</th>
<th>Worker's Gender</th>
<th>Work</th>
<th>Unit cost of work</th>
<th>Job</th>
<th>Attendance</th> {# 1 or less if unit is day, 8 or less if unit is hours #}
<th>Remarks</th> {# if any #}
</tr>
</thead>
<tbody>
{% for result in results %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ result.worker.name }} <input type="hidden" name="workers_pks" value="{{ result.worker.pk }}" id="id_workers_pks_{{ forloop.counter }}"></td>
<td>{{ result.worker.get_gender_display }}</td>
<td>{{ result.work.name }}</td>
<td>{{ result.work.unit_cost }} per {{ result.work.work_unit }}</td>
<td>{{ result.job_handover.job.name }}</td>
<td>
<input type='text' name='attendance_value' id='id_attendance_value_{{ forloop.counter }}' />
</td>
<td>
<input type='text' name='attendance_remarks' id='id_attendance_remarks_{{ forloop.counter }}' />
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
明確にするために、私は次のようなことをすることで値を取得できることを知っています
workers = request.POST.getlist('workers_pks')
attendance_values = request.POST.getlist('attendance_values')
attendance_remarks = request.POST.getlist('attendance_remarks')
私の主な関心事は、どのようにして適切なものを取得するかですattendance_value
。attendance_remarks
workers_pks