Dynamically update Django form field options using Ajax to GET new queryset Dynamically update Django form field options using Ajax to GET new queryset ajax ajax

Dynamically update Django form field options using Ajax to GET new queryset


You can't do this from Django views side, ie, backend. You could try an ajax request for implementing this kind of requests, by sending a GET request to the server for populating the drop-down or whatever you are into.

For a simple example, you could referhere

How do I POST with jQuery/Ajax in Django?

EDIT

def update_subcategories(request):    category = request.GET.get('category', None)    sub_category = list(SubCategory.objects.filter(category__name__exact=category).values('name'))    return JsonResponse(dict(sub_category=sub_category))

Then in ajax response you could grab it like response.data.sub_category


Use ajax to send the category and retrieve subcategory elements.

For the category, send it via get request, and using the orm return the subcategories in a json format which you can show using jQuery.