I have this form:
<div class="form">
<h1>Shift form</h1>
<form method="post" action="{% url 'shift-form' %}">
{% csrf_token %}
<label for="id_status">Status:</label>
<select id="id_status" name="status" class="form-select">
{% for choice in form.status.field.choices %}
<option value="{{ choice.0 }}">{{ choice.1 }}</option>
{% endfor %}
</select>
<label for="id_shift_title">Shift Title:</label>
<input type="text" id="id_shift_title" name="shift_title" class="form-control">
<label for="id_function">Function:</label>
<select id="id_function" name="function" class="form-select">
{% for choice in form.function.field.choices %}
<option value="{{ choice.0 }}">{{ choice.1 }}</option>
{% endfor %}
</select>
<label for="id_start_date">Start Date:</label>
<input type="date" id="id_start_date" name="start_date" class="form-control" onchange="updateEndDate()">
<label for="id_start_time">Start Time:</label>
<input type="time" id="id_start_time" name="start_time" class="form-control">
<label for="id_end_date" style="display: none;">End Date:</label>
<input type="date" id="id_end_date" name="end_date" class="form-control" style="display: none;">
<label for="id_start_time">End Time:</label>
<input type="time" id="id_end_time" name="end_time" class="form-control">
<label for="id_site">Site:</label>
<select id="id_site" name="site" class="form-select">
{% for choice in form.site.field.choices %}
<option value="{{ choice.0 }}">{{ choice.1 }}</option>
{% endfor %}
</select>
<label for="id_user">User:</label>
<select id="id_user" name="user" class="form-select">
{% for choice in form.user.field.choices %}
<option value="{{ choice.0 }}">{{ choice.1 }}</option>
{% endfor %}
</select>
<label for="id_invoiced">Invoiced:</label>
<input type="number" id="id_invoiced" name="invoiced" class="form-control" readonly>
<label for="id_source">Source:</label>
<input type="number" id="id_source" name="source" class="form-control" readonly>
<label for="id_update">Update:</label>
<input type="number" id="id_update" name="update" class="form-control" readonly>
<button type="submit" name="action" value="submit" class="btn btn-primary btn-sm">Submit</button>
</form>
</div>
this is my forms.py:
class ShiftForm(forms.ModelForm):
class Meta:
model = Shift
fields = '__all__'
And this is my view:
def shift_form(request):
if request.method == 'POST':
form = ShiftForm(request.POST)
if form.is_valid():
form.save()
return redirect('weekdays')
else:
form = ShiftForm()
return render(request, 'forms/shiftform.html', {'form': form})
Can I have a extra button with “Save and copy” That will save the record but keeps the form filled to use it for the next entry with small modifications?