[Fixed]-Querying a django DB with model forms

1👍

You need to handle the data differently for the form. Instead of saving it you need to extract the data and query for matching:

def query_queries(request):
    form = QueryForm(request.POST or None)
    if form.is_valid():
        # this is the same as doing
        # Query.objects.filter(studyName=form.cleaned_data['studyName']...)
        queries = Query.objects.filter(**form.cleaned_data)

    context = {
        'queries': queries
    }
    return render(request, "query_queries.html", context)

Leave a comment