Django property field filter

I have one model that contains property fields and I want this field in the filter.

Model KeycloakUser has an email property field.

class KeycloakUser(AbstractKeycloakUser):
    class Meta:
        swappable = "AUTH_USER_MODEL"
        verbose_name = _("User")
        verbose_name_plural = _("Users")

    @property
    def email(self):
        self._confirm_cache()
        return self._cached_user_info.get("email")

above keycloak user model relation with UserProfile model

from django_keycloak.models import KeycloakUser
class UserProfile(CMSMixin, TimeStampMixin, models.Model):
    user = models.OneToOneField(
        KeycloakUser,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="user_profile",
    )

and Django filter is

from iam.models.user_profile import UserProfile


class UserProfileFilter(django_filters.FilterSet):
email = django_filters.CharFilter(field_name="filter_by_email")

it is not working I have used the method field name also.

I’m using Django 4.1 and Python 3.10

Your FilterSet definition isn’t correct. Review the docs and examples at FilterSet Options - django-filter 23.3 documentation

traceback for email field

FieldError at /iam/users/
Cannot resolve keyword 'email' into field. Choices are: aadhar_no, avatar, city, contact_no, country, created_at, dob, gender, gst_no, id, location, pan_no, pincode, sort, state, status, updated_at, user, user_id
Request Method:	GET
Request URL:	http://127.0.0.1:8000/iam/users/?&email=abc%40gmail.com
Django Version:	4.1.12
Exception Type:	FieldError
Exception Value:	
Cannot resolve keyword 'email' into field. Choices are: aadhar_no, avatar, city, contact_no, country, created_at, dob, gender, gst_no, id, location, pan_no, pincode, sort, state, status, updated_at, user, user_id
Exception Location:	/home/it-dev/.cache/pypoetry/virtualenvs/happythoughts-backend-a_ia7cy4-py3.10/lib/python3.10/site-packages/django/db/models/sql/query.py, line 1709, in names_to_path
Raised during:	iam.views.KeycloakUserViewSet
Python Executable:	/home/it-dev/.cache/pypoetry/virtualenvs/h-backend-a_ia7cy4-py3.10/bin/python
Python Version:	3.10.12
Python Path:	
['/home/it-dev/Documents/abc/h-backend',
 '/home/it-dev/Documents/abc/h-backend',
 '/usr/lib/python310.zip',
 '/usr/lib/python3.10',
 '/usr/lib/python3.10/lib-dynload',
 '/home/it-dev/.cache/pypoetry/virtualenvs/h-backend-a_ia7cy4-py3.10/lib/python3.10/site-packages',
 '/home/it-dev/.cache/pypoetry/virtualenvs/h-backend-a_ia7cy4-py3.10/lib/python3.10/site-packages/django_keycloak-0.0.0-py3.10.egg',
 '/home/it-dev/.cache/pypoetry/virtualenvs/h-backend-a_ia7cy4-py3.10/lib/python3.10/site-packages/IPython/extensions']
Server time:	Sat, 04 Nov 2023 11:04:40 +0530