I have a form with a few fields. Most of the time, people only need to change one field every time they submit, not all, so I would like to change it in such a way that upon submission, only the employee field is cleared, but the Work Area choice and station (if there are any available) remain selected.
How could I change the way the form is handled so it is not completely cleared upon submission? I know the form = WarehouseForm()
is what clears it, but I'm not sure how I could just specify I only want the employee_number
field cleared.
views.py
def enter_exit_area(request):
enter_without_exit = None
exit_without_enter = None
if request.method == 'POST':
form = WarehouseForm(request.POST)
if form.is_valid():
emp_num = form.cleaned_data['employee_number']
area = form.cleaned_data['work_area']
station = form.cleaned_data['station_number']
if 'enter_area' in request.POST:
# Submission logic
form = WarehouseForm()
elif 'leave_area' in request.POST:
# Submission logic ..
form = WarehouseForm()
else:
form = WarehouseForm()
return render(request, "operations/enter_exit_area.html", {
'form': form,
'enter_without_exit': enter_without_exit,
'exit_without_enter': exit_without_enter,
})