agateblue / lifter

A generic query engine, inspired by Django ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make nested lookups works on iterables just like django does

agateblue opened this issue · comments

commented

Considering the following structure:

users = [
    'name': 'Kurt',
    'tags': [
        {'name': 'nice'},
        {'name': 'friendly'},
    ]
]

It would be nice if nested lookups allowed us to run queries on the iterable objects, instead of the iterable itself, such as:

manager.filter(tags__name='nice')
# >>> return all users having at least a tag named 'nice'

EDIT:

Ideally, lookups on iterables would also be nestable:

companies = [
    {
        'name': 'blackbooks'
        'employees': [
            {
                'name': 'Manny',
                'tags': [
                    {'name': 'nice'},
                    {'name': 'friendly'},
                ]
            }
        ]
    },
    {
        'name': 'community'
        'employees': [
            {
                'name': 'Britta',
                'tags': [
                    {'name': 'activist'},
                ]
            }
        ]
    }
]

lifter.load(companies)
assert lifter.filter(employees__tags__name='friendly') == companies[0]