Skip to content
Discussion options

You must be logged in to vote

I found that it is possible to use filter lookup for Json fields.
the snippet bellow

items = await Item.filter(data__filter={'some_key__in': ('value1', 'value2')})

Firstly we have to register in lookup to tortoise:

from pypika.terms import Term, BasicCriterion


class In(BasicCriterion):
    def __init__(self, left, right, alias=None) -> None:
        super().__init__('IN', left, right, alias=alias)

    def get_sql(self, quote_char='"', with_alias=False, **kwargs):
        sql = "{left}{comparator}{right}".format(
            comparator=self.comparator,
            left=self.left.get_sql(quote_char=quote_char, **kwargs),
            right=self.right.get_sql(quote_char=quote_char, **kwarg…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@merlinz01
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Soyuzbek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants