I'm interested in what you find. I know TypeDecorator is the right 
solution, I was looking at that for this exact same situation a few weeks 
ago 
( 
https://groups.google.com/forum/#!searchin/sqlalchemy/vanasco%7Csort:date/sqlalchemy/sQtOYxSUiqI/5ns2vWMFaGAJ
 
)

I have a similar situation.  I wrote a generic bitwise wrapper class that I 
was ashamed of, but I guess I should eventually release it.  i can toss it 
on github under the MIT if you'd like.

The way I have my bitwise stuff working is this:

* I create an class that inherits from my `BitwiseSet` class.  That 
subclass stores a mapping of the bitwise values, the parent class has 
functions for common bitwise operations ( add, remove, has_any, has_all -- 
both by string and integer ).   The parent class has an 'encode' and 
'decode' function, which returns an int or list of elements (as int or 
string ).

    class BitwiseClassFieldA(BitwiseSet):
        set_ = {
               'flag_a' << 1,
               'flag_b' << 2,
               'flag_c' << 3,
        }

* I have a property on each of my sqlalchemy objects that works something 
like this...

    class Foo(SqlAlchemyObject):
         bitwise_field_a = sa.Column( sa.Integer, default=0 )
         
         @property
         def bitwise_manager_field_a(self):
                if self._bitwise_manager_field_a is None:
                      self. bitwise_manager_field_a = 
BitwiseClassFieldA(self.bitwise_field_a)
                return self.bitwise_manager_field_a
         _ bitwise_manager_field_a = None

* when i do saves , i call the manager's `encode` function

      instance.bitwise_field_a = instance.bitwise_manager_field_a.encode()


anyways, when I was trying to get a TypeDecorator working, I was focused on 
the Integer field having a decorator and managing my object -- not on 
defining many column attributes like you are.  i think that might be an 
easier avenue, because you want to affect the column itself for these 
comparisons.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to