If you want to display two dropdowns, first one with Client
options and second one with Location
options, with Locations
changing on Client
dropdown change you should add a js event handler, for example with jQuery:
$(document).on('change', '#clients', () => {
...call locations endpoint and update locations options...
})
On backend append your Location
model with a Client
FK and make an endpoint for path app/locations/<int:client_id>/
where you select Locations
based on a Client
:
from django.shortcuts import get_object_or_404
...
def locations(request, client_id):
client = get_object_or_404(Client, id=client_id)
locations = Location.objects.filter(client=client)
return JsonResponse(dict(locations=locations), status=200)