[storm] Storm : Multiple fields request

Gustavo Niemeyer gustavo at niemeyer.net
Wed Nov 12 14:00:22 GMT 2008


Hey Gerdus,

> Some code that I use to do the same thing:
>
> cls = Employee
> param = { 'age':30,'lastname':'smith' }
>
> expressions = []
> for k in param:
>    v = param[k]
>    if v == "none":
>        v = None
>    if hasattr(cls,k):
>        expressions += [ getattr(cls,k) == v ]
>
>
> sl = store.find(cls,And(*expressions))

Except for the None special handling and the check to see if the class
has the attribute, you could just do something like:

    store.find(cls, **param)

Since something like this works:

    store.find(cls, age=30, lastname="smith")

-- 
Gustavo Niemeyer
http://niemeyer.net



More information about the storm mailing list