2006/1/27, tweekgeek <[EMAIL PROTECTED]>:
>
> Hello everyone. I'm trying to figure out how to better do something
> that I've currently got...
>
> I've got a member's table in my database... It currently has a number
> of boolcol fields:
>
> class Member(SQLObject):
> username = StringCol(length=25, alternateID=True)
> appearance_0 = BoolCol(default=False)
> appearance_1 = BoolCol(default=False)
> appearance_2 = BoolCol(default=False)
> appearance_3 = BoolCol(default=False)
>
> ....
>
> I've got a whole load of that type of definition (matching service, if
> you don't know already)... I've got them set up like that because I'm
> using checkboxes for the user to select as many items as they so
> please, and I'd like to allow a user to search for members with an OR
> style search:
>
> where appearance_0 is true, appearance_1 is false, appearance_2
> is true, etc
>
> The nicest solution for this would be if I could search through the
> database with something like:
>
> app = userselectedpreferences
> Member.select(appearance contains app)
>
> As it is right now, I get a nice little list back from the checkboxes
> on my form, and I have to go through it manually:
>
> if 0 in thelist: appearance_0 = True
> if 1 in thelist: appearance_1 = True
> if 2 in thelist: appearance_2 = True
>
> It's a pain, to say the least, and if I have to add or remove an item
> from the list, it could give me some big headaches.
For OR search, you can do:
thelist = [0, 2, 5]
query = True
for el in thelist:
query = OR(query, getattr(Member.q, 'appearance_%s' % el) == True)
Member.select(query)
But I think the better solution will be to add extra 1:N table for
"keeping up appearances" ;-)
--
Ksenia