Awesome!  That is exactly what I needed - thanks very much!

On Jun 30, 8:06 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
> your question has arrived at the same time almost the exact same question is 
> coming from another user Russ, so I've added an example of how to use 
> attribute events in conjunction with a TypeDecorator, so that the data is 
> coerced both at the database level, as well as at the attribute setter level 
> - this is 
> athttp://www.sqlalchemy.org/trac/wiki/UsageRecipes/ValidateAllOccurrenc....
>
> On Jun 29, 2011, at 9:40 PM, Jason Denning wrote:
>
> > 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 sqlalchemy@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

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

Reply via email to