'Create the proper SQL fragment. This inserts something like
"(T0.flags & value) != 0".
This will be called by Where.as_sql()'

def as_sql(self, qn, connection=None):

    if self.bit:
        return (('(%s.%s    |    %d)' % (qn(self.table_alias), qn(self.column), self.bit.mask)), [])
    return (('(%s.%s    &    %d)' % (qn(self.table_alias), qn(self.column), self.bit.mask)), [])
