I am having issues creating a read-only column using column_property.
I have a phone table that has the columns: id, country_code, number,
and deleted. I want to have an international column which will be set
to True or False (or 1 or 0) depending on the value of the
country_code. Provided below is the snippet of code to work with:
phone_table = Table('phones', metadata,
Column('id', Integer, primary_key=True),
Column('country_code', String(5)),
Column('number', String(20)),
Column('deleted', Boolean, default=False),
)
class Phone(object):
pass
# international gets set to True or None which isn't intended
# also the session is from turbogears.database import session
session.mapper(Phone, phone_table, properties={
'international':column_property((phone_table.c.country_code=='1').label('international'))
})
I'm not sure if this is a Turbogears issue or SQLAlchemy issue but the
international field is always None when I do the following: I
instantiate a Phone object, populate the attributes, session.save the
instantiated Phone object, session.flush, and then query the new Phone
object.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---