# Django property field filter

**URL:** <https://forum.djangoproject.com/t/django-property-field-filter/25012>\
**Category:** Forms & APIs\
**Created:** [November 3, 2023, 12:21pm UTC](https://forum.djangoproject.com/t/django-property-field-filter/25012 "2023-11-03T12:21:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangeshchavan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mangeshchavan/32/16807_2.png) [@mangeshchavan](https://forum.djangoproject.com/u/mangeshchavan)\
**Post date:** [November 3, 2023, 12:21pm UTC](https://forum.djangoproject.com/t/django-property-field-filter/25012/1 "2023-11-03T12:21:40Z")

</div>

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

Model KeycloakUser has an email property field.

```auto
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

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 3, 2023, 12:59pm UTC](https://forum.djangoproject.com/t/django-property-field-filter/25012/2 "2023-11-03T12:59:02Z")

</div>

Your `FilterSet` definition isn’t correct. Review the docs and examples at [FilterSet Options - django-filter 23.3 documentation](https://django-filter.readthedocs.io/en/latest/ref/filterset.html)

---

<div class="post-metadata">

**Author:** ![mangeshchavan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mangeshchavan/32/16807_2.png) [@mangeshchavan](https://forum.djangoproject.com/u/mangeshchavan)\
**Post date:** [November 4, 2023, 5:35am UTC](https://forum.djangoproject.com/t/django-property-field-filter/25012/3 "2023-11-04T05:35:34Z")

</div>

traceback for email field

```auto
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

```
