Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Maybe add a way to check if one item of a list of values exists #164

Closed
@msiemens

Description

@msiemens

Raised inhttps://forum.m-siemens.de/d/29-how-to-use-matches-with-int-values

Basically, withany andall we check, if a document's field – which is a list of values – contains a given value or only is a given value. From the docs:

>>>db.search(User.groups.any(['admin','sudo']))[{'name':'user2','groups': ['admin','user']}, {'name':'user3','groups': ['sudo','user']}]>>>db.search(User.groups.all(['admin','user']))[{'name':'user2','groups': ['admin','user']}]

Note how in this case the field we check is a list. Now, right now we don't have a way for the reverse operation: if the field is a value, check if it's contained in a list. It could be something like this:

>>>db.search(User.name.in(['admin','user']))[{'name':'admin'}][{'name':'user'}]

The issue is mainly naming. We can't name the methodin as it's a Python keyword. I'm torn between calling itpart_of orcontained_in but both aren't exactly really intuitive when I think about it.


By the way, the workaround for now is using a custom test function:

>>>db.search(User.name.test(lambdaname:namein ['admin','user']))[{'name':'admin'}][{'name':'user'}]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp