# Custom field filters

**URL:** <https://talk.getindico.io/t/custom-field-filters/4173>\
**Category:** Development\
**Created:** [June 21, 2025, 10:10pm UTC](https://talk.getindico.io/t/custom-field-filters/4173 "2025-06-21T22:10:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Staacks](https://talk.getindico.io/user_avatar/talk.getindico.io/staacks/32/1875_2.png) [@Staacks](https://talk.getindico.io/u/Staacks)\
**Post date:** [June 21, 2025, 10:10pm UTC](https://talk.getindico.io/t/custom-field-filters/4173/1 "2025-06-21T22:10:47Z")

</div>

I have created a plugin with a rather complex custom registration form field (see [User-friendly presentation of custom registration field data](https://talk.getindico.io/t/user-friendly-presentation-of-custom-registration-field-data/4125) for the background story). Now my colleagues want to filter by some of its properties.

I found that I could easily achieve what they want by setting up a list of filter options via `filter_choices` and then assemble matching filters in `create_sql_filter`.

The only problem is that if I try to use that filter, my selection for the filter is ignored and `create_sql_filter` is never called. The reason for this seems to be that Indico only accepts filters from some specific default fields despite being able to handle custom filters from `create_sql_filter`. Specifically, in [indico/modules/events/lists.py line 148](https://github.com/indico/indico/blob/bc983ee0e4c6cf6b6aee3a4f4346fbd858ebf093/indico/modules/events/registration/lists.py#L148) it only parses filters from a narrow list of fields.

When I extend this to also allow filters from any field that implements `create_sql_filter` I can achieve exactly what I want:

```auto
        for field in self.regform.form_items:
            hasCustomFilter = (hasattr(field, "field_impl") and hasattr(field.field_impl, "create_sql_filter"))
            if field.is_field and (field.input_type in {'single_choice', 'multi_choice', 'country', 'bool', 'checkbox',
                                                       'sessions'} or hasCustomFilter):
                options = request.form.getlist(f'field_{field.id}')

```

So: Am I missing the official way to get my filter to work or is this a change I should submit as a PR? Am I missing something where my solution could break?

---

<div class="post-metadata">

**Author:** ![ThiefMaster](https://talk.getindico.io/user_avatar/talk.getindico.io/thiefmaster/32/509_2.png) [@ThiefMaster](https://talk.getindico.io/u/ThiefMaster)\
**Post date:** [June 21, 2025, 10:17pm UTC](https://talk.getindico.io/t/custom-field-filters/4173/2 "2025-06-21T22:17:09Z")

</div>

My suggestion would be to remove that check for the field list and instead add a `allow_filtering` attribute to `RegistrationFormFieldBase` (set it to `False` there) and then in all the field classes that match the current hardcoded list, set it to `True`. Then change the code to check for that, instead of the list.

PS: A field class always has `create_sql_filter`, so the `hasattr` check would always succeed.

---

<div class="post-metadata">

**Author:** ![Staacks](https://talk.getindico.io/user_avatar/talk.getindico.io/staacks/32/1875_2.png) [@Staacks](https://talk.getindico.io/u/Staacks)\
**Post date:** [June 22, 2025, 6:06am UTC](https://talk.getindico.io/t/custom-field-filters/4173/3 "2025-06-22T06:06:21Z")

</div>

> A field class always has `create_sql_filter` , so the `hasattr` check would always succee

Oops, missed that. But what does this check protect against anyway? The user can only set filters for those fields that define options and it should not be a security issue as fiddling with the request only gets you a non-working filter with the harmless generic `create_sql_filter` query. So, is `allow_filtering` even required or should the `input_type` check just be removed?

---

<div class="post-metadata">

**Author:** ![ThiefMaster](https://talk.getindico.io/user_avatar/talk.getindico.io/thiefmaster/32/509_2.png) [@ThiefMaster](https://talk.getindico.io/u/ThiefMaster)\
**Post date:** [June 23, 2025, 9:50am UTC](https://talk.getindico.io/t/custom-field-filters/4173/4 "2025-06-23T09:50:37Z")

</div>

No, I don’t think there would be any risk with that.

Instead of the new attribute you could also check if the field’s `filter_choices` is not falsy. Depending on the field this may trigger extra queries, but this is OK here since it’s only needed when saving the filter settings, and when displaying the dialog the this attribute is also used to determine whether filter options should be shown.
