also your example should read like this:

a = session.query(A).all()[0]
print a.time_units
a.time_units = 1
print a.time_units
#print A.timeunits
#print A.time_units

the A.time_units is the class-bound descriptor so that raises an  
exception due to a missing __str__() method.  this is a small bug but  
does not break the functionality you're looking for.   The in-python  
access to the attribute is performed via the attribute you've created,  
i.e. a.time_units.


On Jan 26, 2009, at 12:59 PM, Toby Bradshaw wrote:

> CREATE TABLE example_a
> (
>  id integer NOT NULL,
>  time_units integer,
>  CONSTRAINT example_a_pkey PRIMARY KEY (id)
> )
>
> and (based on
> http://www.sqlalchemy.org/docs/05/mappers.html#using-descriptors):
>
> from sqlalchemy import *
> from sqlalchemy.orm import sessionmaker, mapper, synonym
>
> class A(object):
>  def _set_t(self, t):
>    print "SET"
>    self.timeunits = t / float(10)
>  def _get_t(self):
>    print "GET"
>    return self.timeunits * 10
>  time_units = property(_get_t, _set_t)
>
> engine = create_engine("postgres://tobe:<snip>@localhost/test")
> engine.echo = False
>
> session_class = sessionmaker(
>  bind = engine, autoflush = True, autocommit = False,
> )
>
> meta = MetaData(bind = engine)
> table_A = Table("example_a", meta, autoload = True)
>
> print A.time_units
> mapper(A, table_A, properties = {
>  "time_units" : synonym("timeunits", map_column = True)
> })
>
> session = session_class()
>
> a = session.query(A).all()[0]
> print a.timeunits
> a.timeunits = 1
> print a.timeunits
> print A.timeunits
> print A.time_units


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