I was able to get a multiple select box working for edit mode:
<section class="container">
<div>
<select id="leftValues" size="5" multiple></select>
</div>
<div>
<input type="button" id="btnLeft" value="<<" />
<input type="button" id="btnRight" value=">>" />
</div>
<div>
<select id="rightValues" size="4" multiple>
{% for device in devices %}
<option>{{ device }}</option>
{% endfor %}
</select>
</div>
</section>
<div>
<input type="text" id="txtRight" />
</div>
</section>
<button type="submit" id="save">Save Changes</button>
<!--button type="cancel">Cancel</button-->
<a href="{% url 'inventory:display_maintenance' %}" ><button type="button">Maintenance Page</button></a>
</form>
<link rel="stylesheet" href="{% static 'css/msb.css' %}">
<script>
$("#btnLeft").click(function () {
var selectedItem = $("#rightValues option:selected");
$("#leftValues").append(selectedItem);
});
$("#btnRight").click(function () {
var selectedItem = $("#leftValues option:selected");
$("#rightValues").append(selectedItem);
});
$("#rightValues").change(function () {
var selectedItem = $("#rightValues option:selected");
$("#txtRight").val(selectedItem.text());
});
But when I select the save button, after making changes to the table, again in the template, edit_maintenance.html, it does not feed into the database.
The code in the views.py that relates to this is as follows:
def edit_maintenance(request, id): license_key = Maintenance.objects.get(id=id) maintenance_form = MaintenanceForm(instance=license_key) devices = Devices.objects.filter(maintenance = id) if request.method == 'POST': print(request.POST) maintenance_form = MaintenanceForm(request.POST, instance=license_key) if maintenance_form.is_valid(): maintenance_form.save() # return redirect('maintenance:edit_maintenance', id) args = { 'maintenance_form' : maintenance_form, 'devices' : devices } return render(request, 'inventory/edit_maintenance.html', args)
I'm still fairly new to this so any tips, examples, would be great.