Hi All,
I am building a Pyramid app using SQLAlchemy for the model, and I
would like to be able to use the attributes as full-fledged objects
(i.e., I would like to be able to define methods attached to the
attributes), ideal example usage (although this is a somewhat
contrived example):

class Phone(Base):
    id = Column(Integer, primary_key=True)
    phone = Column(MyPhoneType)

>>>p1 = Phone(phone="9995551212")
>>>session.add(p1)
>>>p1.phone
'9995551212'
>>>p1.phone.prettyPrint()
"(999) 555-1212"
>>>p1.phone.foo()
"Now doing foo..."

I have made some attempts towards this end using TypeDecorator and by
trying to extend UserDefinedType, but it seems that the instantiated
objects always have their mapped attributes converted into regular
python types (string, unicode, etc..) losing whatever methods/class
level stuff I try to define.

I am not trying to affect any aspect of the descriptor protocol,
object management, database interaction or any other ORM type stuff -
I just want some helper methods, and maybe some instance-level
attributes to be available for certain types of mapped attributes.

Is this possible?  Should I be doing this using TypeDecorator /
UserDefinedType / other ?  Is anyone else attempting this type of
thing, or am I totally crazy?

Thanks,
Jason

-- 
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