Does Django have an accessible list of all valid field lookup operators (those that are used by the QuerySet API, e.g. 'contains', 'in', 'lt', etc)?
Thanks
EDIT: For clarification, I mean an in-code list that I can import so, for example, I can check if a given string matches a valid operator.
After searching the source for the operators, it lives in django.db.models.sql.constants.QUERY_TERMS
.
A dictionary with lookup strings mapped to None
.
'exact' in QUERY_TERMS
Thanks for this! Never would have gone looking, but I could definitely use this.
As of Django 2.1, django.db.models.sql.constants.QUERY_TERMS
constant is removed. Per the release notes, Django recommends the get_lookups()
method of the Lookup Registration API as an alternative.
For a given field on a model, it can be accessed via:
MyModel._meta.get_field('my_field').get_lookups()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With