Michael (Or anyone else),

sorry I have to get back on this. I renamed all Columns in my application 
definitions to MyColumn a while back. and everything worked.
Now that I'm starting to use functionality of MyColumn. (The reason I needed 
this) I run into some trouble.

What do I want:

I want to add properties to the Column definition, properties which vane 
NOTHING to do with SA, but should not break the inner workings of SA.
The Properties should be initialized and dealt with by MyColumn


Michael pointed at setting _constructor to Column (See mail history below)

class MyColumn(Column):
        _constructor = Column
        X       =  0
        Y       =  0

class Test(Base, GeneratorClass):
        __tablename__ = …..
        etc...
          Name          =         MyColumn(Uncicode(100), Index=True, 
Last_of_SQLAlchemy_properties, X = 100, Y = 200) 



Note the X and Y (Which will be the position on screen, as I will generate 
screens directly using the GeneratorClass.__subclasses__ and a lots of 
Introspection from within SA (reflection.Inspector.from_engine(engine) )and 
python.

Te above, you mentioned is not working for me. The X and Y are passed to the 
_contructor.__init__ directly and class property Test.Name looses track of them

I need something like:

class MyColumn(Column)

        def __init__(self, Type, **options)
                #filter all options to set to this column and have nothing to 
do with SA (Like X and Y)
                FilteredOptions = {}
                For option in options:
                        if hasattr(self, option.name)
                                #init self 
                        else:
                                #add to Filteredoptions
                #Now Init the Superclass:Column with the correct properties
                Column.__init__(self,Type, *Filteredoptions)



At the other end, I might need to introspect the objects, I have tried but I 
have trouble in relating to X or Y since the Name Column is an 
InstrumentedAttribute.


One other thing. I can get Columns by iterating over self.__table__.Columns. I 
can get Foreign keys using:
inspector.get_foreign_keys(SomeClass.__tablename__)

But Now I need to access the relation objects defined in my classes and 
Introspect them.
There just does not seem to be a Class.__table__.relations, neither see I 
something in the documentation but I might overlook something, not sure…

Martijn



On Feb 28, 2011, at 18:21 , Michael Bayer wrote:

> Column can be subclassed but because they are intensively used in complex 
> expression transformations, your custom class may be used in more scenarios 
> than you first anticipate.
> 
> There are two scenarios where Column objects are copied, and in one case 
> copied into an altered class, so the "copying" of Column uses an attribute 
> called _constructor to point to which class should be used when creating this 
> copy.  Usually setting that to Column:
> 
> class MyColumn(Column):
>    _constructor = Column
> 
>   # .... go nuts
> 
> is all you need.   
> 
> 
> 
> On Feb 28, 2011, at 10:17 AM, Martijn Moeling wrote:
> 
>> Hi,
>> 
>> I know this is an "OLD" threat but I was searching the group to see If I was 
>> not the first one doing this.
>> 
>> I am not sure I understand very well what this threat is all about, but I 
>> want to extend the Column class for a different reason.
>> 
>> I want to add extra functionality to the Column class which is absolutely 
>> NOT SA related. SA functionality should not be effected though.
>> 
>> say I want to add a config value and some methods for rendering and 
>> validating screens:
>> 
>> def MyColumn(Column):
>> 
>>      def __init():
>>              dosomething to init
>> 
>>      def ExtraInfo(self):
>>              do_something_not_sa_related
>> 
>>      validation = 'someregex'
>> 
>> 
>> and use MyColumn in places where I normally use Column(......)
>> 
>> What do I need to take into account, I've done some tests and "Error hell" 
>> broke loose, where the errors are hidden deep inside SA so hard to overcome.
>> 
>> Martijn  
>> 
>> On Dec 11, 2008, at 16:20 , Michael Bayer wrote:
>> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to