# Django serializer data filter multiple values by Forms

**URL:** <https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634>\
**Category:** Forms & APIs\
**Created:** [September 5, 2023, 1:44pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634 "2023-09-05T13:44:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tornike1989](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tornike1989/32/15082_2.png) [@Tornike1989](https://forum.djangoproject.com/u/Tornike1989)\
**Post date:** [September 5, 2023, 1:44pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634/1 "2023-09-05T13:44:08Z")

</div>

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.

```auto
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))

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 5, 2023, 2:27pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634/2 "2023-09-05T14:27:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tornike1989](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tornike1989/32/15082_2.png) [@Tornike1989](https://forum.djangoproject.com/u/Tornike1989)\
**Post date:** [September 5, 2023, 4:21pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634/3 "2023-09-05T16:21:59Z")

</div>

Thanks for the feedback.

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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 5, 2023, 4:30pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634/4 "2023-09-05T16:30:44Z")

</div>

> [@Tornike1989](#):
>
> using multiple forms.

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

Your base query appears to be:

> [@Tornike1989](#):
>
> `mydata = models.FlatModelSqlite.objects.all()`

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.

---

<div class="post-metadata">

**Author:** ![Tornike1989](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tornike1989/32/15082_2.png) [@Tornike1989](https://forum.djangoproject.com/u/Tornike1989)\
**Post date:** [September 5, 2023, 4:54pm UTC](https://forum.djangoproject.com/t/django-serializer-data-filter-multiple-values-by-forms/23634/5 "2023-09-05T16:54:21Z")

</div>

Yes, I think I found it:

```auto
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.
