[SQLObject] Looking for selection hints
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Frank B. <fb...@fo...> - 2003-10-26 22:52:49
|
Hi all,
I could need a little help with understanding how to build
SQLObject selections dynamically.
So far, I have a dictionary that describes the criteria to search the
DB. Keys are my Columns, values are lists of search words. Like this:
{'title': ['rock'], 'format': ['cd'], 'artist': ['strokes', 'the']}
That should become like this:
results = Product.select( AND(
LIKE(Product.q.title, "rock"),
LIKE(Product.q.format, "cd"),
LIKE(Product.q.artist, "strokes"),
LIKE(Product.q.artist, "the") ))
I know I could do something like
eval(""" LIKE(Product.q.%s, "%s" """, (key, value))
but this is so ugly, it just feels very wrong. I also could build the
SQL directly, but this feels still a little bit wrong, although might
be okay.
My main problem is: How do I do the mapping between attribute names
(like the keys in my dict) and the attributes themselves (like
Product.q.title or Product.title)? Is there some introspection
available? I found the _SO_columnDict but this didn't help much yet.
But then maybe it's just late.
Anyway I'd love to hear some opinions on this.
ciao
--
Frank Barknecht _ ______footils.org__
|