Michael,

On 24/01/2010 15:28, Michael Bayer wrote:
...
have you considered 
http://www.sqlalchemy.org/docs/mappers.html#building-query-enabled-properties ?
No - had not found that.

Needed a bit to figure it out. I am using declarative and ended up with this.

Michael, thanks a lot, I think I am getting there, the following works for me, maybe it is useful for others.

class Country_B(Base):
    __table__ = sa.Table(u'countries_b', metadata,
sa.Column(u'id', sa.Integer(), sa.Sequence('countries_b_id'), primary_key=True, nullable=False),
    sa.Column(u'iso2', sa.String(length=2, convert_unicode=False)),
    sa.Column(u'iso3', sa.String(length=3, convert_unicode=False)),
    )

    def _get_translation(self):
        try:
x = sao.object_session(self).query(Country_T).with_parent(self).filter(Country_T.lang_code5==getCurrentUserLang)
##            print 'def: %s' % x
##            print 'def: %s' % getCurrentUserLang()
            return x.one()
        except sao.exc.NoResultFound:
            try:
x = sao.object_session(self).query(Country_T).with_parent(self).filter(Country_T.lang_code5==getDefaultUserLang)
##                print 'def: %s' % x
##                print 'def: %s' % getDefaultUserLang()
                return x.one()
            except sao.exc.NoResultFound:
                return 'no translation found'

    country_t = sao.relation('Country_T', backref='country_b')

    country = property(_get_translation)

Next thing is to make "_get_translation" reusable for different tables.

Werner

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