首页 > 解决方案 > Django/Python Where to find a list of available filter functions when querying

问题描述

I'm currently working with a Python Django project and in there I filter data from PostgreSQL where I need to find the functions that can be called after each field followed by two underscores.

Ex:

Like wise from where can we get a list of all possibilities (except for foreign key fields) that can be called through the TestObj.objects.filter() ?

标签: pythondjangodjango-queryset

解决方案


These are called field lookups [Django-doc]. You can find a list of builtin field lookups in the documentation on querysets. When writing this answer, the current list of builtin lookups is:

Note that you can implement your own field lookup [Django-doc] as well. Indeed, you can define a lookup and how to map that to a database query. Certain Django packages for example might provide an extra set of field lookups.

The set of lookups is thus not "fixed". You can add lookups if you often need to retrieve/filter a certain condition, and there exists no builtin lookup for that.


推荐阅读