Generate URL Filter-squashed#2882
Conversation
samuelhwilliams
left a comment
There was a problem hiding this comment.
I think my main issue here is on the implementation being that the URL value is baked into the Filter definition. I'm not sure this feels like the right developer experience/API.
I think we should take this back to an issue and plan out the implementation up front rather than do it on a PR.
I think I'd be more interested in something like this:
filtered_url = view.url_for(
search="exam",
filters=[
(filters.FilterLike(Model1.test1, "Email"), "@example.com"),
(filters.BooleanEqualFilter(Model1.bool_field, "active"), False),
(filters.FloatGreaterFilter(Model1.test5, "Salary", 15.3),
],
)Ideally with full type support so that type checkers can statically verify that you've passed the correct argument type for the appropriate filter, ie boolean values for a Boolean filter and string values for a like filter.
There was a problem hiding this comment.
The changes to this example aren't needed as part of this PR - ideally we would keep PRs small and scoped to help review. This could have gone in separately if it's just for general example behaviour unrelated to generating URL filters.
There was a problem hiding this comment.
simply i wanted to add some records to test the filter's js behavior. as you know filters input fields are fully created by JS and there is no way to test them using pytest. I think changes in this example accelrate testing the filter.
|
now this style is adapted. you can check and review |
commit 3e99002e0e9dc46a0eac40961950490e7387bc42 Merge: e2e0092 c8ac222 Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Sun May 24 10:12:20 2026 +0300 Merge branch 'master' into url-filter11 commit e2e0092 Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Sat May 16 08:07:07 2026 +0300 refactor: remove url_value parameter from filter classes and update related code commit ab022e1 Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Wed May 13 22:18:38 2026 +0300 fix typing commit a864bb7 Merge: 51c81b7 23be1ac Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Wed May 13 21:35:37 2026 +0300 Merge branch 'master' into url-filter11 commit 51c81b7 Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Wed May 13 21:11:11 2026 +0300 fix conflicts commit 8cdccec Author: Sami Alfattani <Sami_alfattani@hotmail.com> Date: Mon Apr 27 21:56:56 2026 +0300 Generate URL Filter This PR adds a function to generate a URL with filter arguements including all types of filters (Like, NotLike, Greater....etc) and including both indexed (`flt2_3=xx`) and named (`flt3_email_like=@example.com`) **Usage:** ``` filtered_url = view.url_for( search="exam", filters=[ filters.FilterLike(Model1.test1, "Email", url_value="@example.com"), filters.BooleanEqualFilter(Model1.bool_field, "active", url_value=False), filters.FloatGreaterFilter(Model1.test5, "Salary", url_value=15.3), ], ) ``` **Output:** `/admin/user/?search=exam&flt0_0=@example.com&flt1_21=0&flt2_16=15.3` **OR with named parameters:** `/admin/user/?search=exam&flt0_test1_contains=@example.com&flt1_bool_field_equals=0&flt4_test2_greater_than=15.3`
e2e0092 to
df827ea
Compare
| return "1" if value else "0" | ||
|
|
||
|
|
||
| class BaseEmptyFilter(BaseBooleanFilter): |
Fixes #2703
This PR adds a function to generate a URL with filter arguements including all types of filters (Like, NotLike, Greater....etc) and including both indexed (
flt2_3=xx) and named (flt3_email_like=@example.com)Usage:
Output:
/admin/user/?search=exam&flt0_0=@example.com&flt1_21=0&flt2_16=15.3Output with named parameters:
/admin/user/?search=exam&flt0_test1_contains=@example.com&flt1_bool_field_equals=0&flt4_test2_greater_than=15.3