[Solved]-Meta.fields contains a field that isn't defined on this FilterSet: ****

14👍

See this for a good explanation.

When you do queryset.filter(field_name=field_value), Django translates that into a SQL query. Unfortunately, calculated properties only live on the Python object, so you can’t filter by them.

The workaround is to, whenever you filter by one of these, include an annotation to your queryset that adds the proper field in SQL. The link has a good example of how to do this. It’s harder than doing it in Python, but the only way to go really.

Leave a comment