Some possible way to investigate :

1. using a binary mask instead of several columns
class Member(SQLObject):
    username = StringCol(length=25, alternateID=True)
    appearances_mask = IntCol(default=0)

    #if you want provide compatibility, create computed property
    def _get_appearance_0(self):
        return self.appearance & (2**0)

    def _get_appearance_1(self):
        return self.appearance & (2**1)

    ...

   #create mask from check box:
   mask = 0
   for x in thelist:
       mask =mask | (2**int(x))

2. only modify your checkbox read
   # to set or create memeber
   data = {}
   for x in thelist:
       data['appearance_' + x] = True
   member.set(data)

   #to search member
Member.select(where=sqlbuilder.AND(['appearance_' + x + '= TRUE' for x in thelist])

Expect that could help you to find trick


tweekgeek a écrit :
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.

I'm leaving this very vague, because I'd like to know how others have
approached problems such as this one (but not necessarily the exact
same thing)... Sorry if I haven't explained enough of it, I'll provide
further details if needed.. I also figure that since I'm really quite a
novice with programming in python, there's probably a very elegant
solution available that I just don't know how to find.

Thanks everyone!

_________________________________
http://kassemi.blogspot.com



--
--------------------------------------------------------------
David "Dwayne" Bernard            TurboHtmlPy creator

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to