# Filtering rows in the changelist\_view method of the admin.ModelAdmin class

**URL:** <https://forum.djangoproject.com/t/filtering-rows-in-the-changelist-view-method-of-the-admin-modeladmin-class/25336>\
**Category:** The Admin\
**Created:** [November 14, 2023, 3:46pm UTC](https://forum.djangoproject.com/t/filtering-rows-in-the-changelist-view-method-of-the-admin-modeladmin-class/25336 "2023-11-14T15:46:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quant12345](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/quant12345/32/17091_2.png) [@quant12345](https://forum.djangoproject.com/u/quant12345)\
**Post date:** [November 14, 2023, 3:46pm UTC](https://forum.djangoproject.com/t/filtering-rows-in-the-changelist-view-method-of-the-admin-modeladmin-class/25336/1 "2023-11-14T15:46:56Z")

</div>

Hi, everyone!  
I managed to create a form in the admin through which I receive dates. The template is redefined and is located: `templates/admin`. But I can’t filter the output records like I can do with `get_queryset`.  
In general, I need to: get data from the form and filter the rows in the admin.  
How to do this in `changelist_view` method?

I tried this, but it doesn’t change anything:

```auto
qs = Abc.objects.filter(id__gte=3)
response.context_data['cl'].queryset = list(qs)

```

admin.py

```auto

class Abc_Admin(admin.ModelAdmin):
    list_display = ('id',)
    change_list_template = 'admin/change_list.html'

    def changelist_view(self, request, extra_context=None):
        response = super().changelist_view(
            request,
            extra_context=extra_context,
        )

        if request.method != 'POST':
            response.context_data['form'] = TestForm()
        else:
            form = TestForm(request.POST)
            if form.is_valid():
                response.context_data['form'] = form
                val = [form.cleaned_data.get('start'), form.cleaned_data.get('end')]
                qs = Abc.objects.filter(id__gte=3)
                response.context_data['cl'].queryset = list(qs)

                return super().changelist_view(request, extra_context=response.context_data)

        return response

admin.site.register(Abc, Abc_Admin)

```

template

```auto
{% extends 'admin/change_list.html' %}

{% block result_list %}
<form action='' method='POST'>
    {% csrf_token %}
    {{ form.as_p }}
    <input type='submit' value='adding'/>
</form>

{{block.super}}

{% endblock %}

```

form.py

```auto
class TestForm(forms.Form):
    start = forms.DateField(widget=forms.SelectDateWidget(years=range(2022, 2025)))
    end = forms.DateField(widget=forms.SelectDateWidget(years=range(2022, 2025)))

```

---

<div class="post-metadata">

**Author:** ![quant12345](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/quant12345/32/17091_2.png) [@quant12345](https://forum.djangoproject.com/u/quant12345)\
**Post date:** [November 15, 2023, 9:57am UTC](https://forum.djangoproject.com/t/filtering-rows-in-the-changelist-view-method-of-the-admin-modeladmin-class/25336/2 "2023-11-15T09:57:36Z")

</div>

Found a solution: `response.context_data['cl'].result_list = list(qs)`
