Filter not appearing in django-import-export

I implemented django-import-export and tried to customer the export form with start_date and end_date filter, but it is not appearing on the export view.

here is a snippets of my code. TIA

forms.py

from django import forms
from import_export.forms import ExportForm

class CustomExportForm(ExportForm):
    start_date = forms.DateTimeField(required=False, label="Start Date", help_text="Format: YYYY-MM-DD HH:MM:SS")
    end_date = forms.DateTimeField(required=False, label="End Date", help_text="Format: YYYY-MM-DD HH:MM:SS")

here is my resource.py

class SMSMessageResource(resources.ModelResource):
    sender = fields.Field(
        column_name='sender',
        attribute='session',
        widget=ForeignKeyWidget(Model2, 'sender')
    )
    def __init__(self, **kwargs):
        super().__init__()
        self.start_date = kwargs.get("start_date")
        self.end_date = kwargs.get("end_date")

    def filter_export(self, queryset, **kwargs):
        if self.start_date and self.end_date:
            return queryset.filter(created__range=[self.start_date, self.end_date])
        return queryset
    
    class Meta:
        model = Model1
        fields = ('id', 'sender', 'created', 'sms', 'synced')
        export_order = ('id', 'sender', 'created', 'sms', 'synced')

and this in my admin.py

def get_export_resource_kwargs(self, request, **kwargs):
        export_form = kwargs.get("export_form")
        if export_form:
            kwargs.update(
                start_date=export_form.cleaned_data.get("start_date"),
                end_date=export_form.cleaned_data.get("end_date")
            )
        return kwargs

What I want to achieve is, apply a date range filter on my export. but the filters don't show on the export view.

Back to Top