Django serializer data filter multiple values by Forms

Hello,
I have Forms and want to use it during @api_view.
Currently, I am getting the all data, I want it to be filtered based on the Forms.

I want to filter serializer_class.data by Forms.

class ForecastField_all(forms.Form):
    flat_Ad = forms.ChoiceField(choices=flat_Adress)
    flat_P = forms.ChoiceField(choices=flat_project)
    flat_Stat = forms.ChoiceField(choices=flat_Status)


@api_view(['GET', 'POST'])
def all_flat(request):
    mydata = models.FlatModelSqlite.objects.all()
    serializer_class = serializers.FlatSerializerSqlite(mydata, many=True)

    if request.method == "GET":
        form_all_flat = ForecastField_all(request.GET)

        if form_all_flat.is_valid():
            all_fl_flatP = form_all_flat.cleaned_data['flat_P']
            all_fl_flatAd = form_all_flat.cleaned_data['flat_Ad']
            all_fl_flat_Stat = form_all_flat.cleaned_data['flat_Stat']

            .....

            html_save = "MyHome/all_flat.html"
            template = loader.get_template(html_save)
            context = {
                'data': serializer_class.data, 'flatP': ForecastField_all()
            }
            return HttpResponse(template.render(context, request))

How are you issuing the request to this view? What exactly is happening? Are you getting any error messages? If so, post it along with the full traceback.

Thanks for the feedback.

I’m not getting an error, I just want to filter the data retrieved from the database using multiple forms.

I think you mean “multiple fields” here? Or are you referencing something else?

Your base query appears to be:

You would want to perform that query after you have retrieved the form values, and use those values in a filter clause in that query.

Yes, I think I found it:

all_insts = models.FlatModelSqlite.objects.filter(
                     flat_Ad =form_all_flat.cleaned_data['flat_Ad'], 
                     all_fl_flatP =form_all_flat.cleaned_data['flat_P']......)
    

Tomorrow, I will test at work.