silentsokolov / django-admin-rangefilter

A Django app that lets you filter data by date range and numeric range in the admin UI
MIT License
713 stars 106 forks source link

Range Filter by two fields #69

Closed W0rtX closed 2 years ago

W0rtX commented 2 years ago

Hello, thank you for your code!

Could you tell, how i can range filter by two fields?

My model have fields: created and finished. If i add filter into list filter in django-admin, i receive next url: ?q=&created_atrangegte_0=2021-10-01&created_atrangegte_1=22%3A00&created_atrangelte_0=2021-10-03&created_atrangelte_1=8%3A00

But i need next url: ?q=&created_atrangegte_0=2021-10-01&created_atrangegte_1=22%3A00&finished_atrangelte_0=2021-10-03&finished_atrangelte_1=8%3A00

Is there a simple way to do this? Thanks

silentsokolov commented 2 years ago

Show your ModelAdmin

W0rtX commented 2 years ago

from rangefilter.filter import AdminSplitDateTime, DateTimeRangeFilter as OriginalDateTimeRangeFilter class TaskAdmin(admin.ModelAdmin): list_display = ( 'created_at', 'finished_at', ) list_filter = ( ('created_at', OriginalDateTimeRangeFilter), )

silentsokolov commented 2 years ago
list_filter = (
    ('created_at', OriginalDateTimeRangeFilter),
    ('finished_at', OriginalDateTimeRangeFilter),
)

Does it not work?

W0rtX commented 2 years ago

This works, but two filters are created: by creation date and by finished date, and I need to make sure that these two fields are combined in one filter: DateFrom is compared with the creation date, and DateTo with the finished date

silentsokolov commented 2 years ago

Please check version from the master branch