Is there an easier way? I discovered this as a really hacky way of just representing a record.
class Address(.....) ... class Person(db.Model): name = Column(String(255)) id_address = Column(ForeignKey('address.id'), info=dict(represent=lambda id: Address.query.get(id).street)) And to get this.... me = Person.query.get(1) for col in Person.__table__.c: if col.info.has_key('represent'): print col.info['represent'](getattr(me, col)) else: print getattr(me, col) -- Thadeus On Fri, Sep 3, 2010 at 1:40 PM, Thadeus Burgess <thade...@thadeusb.com> wrote: > Is there a way to specify the way a column represents itself when > converted to string? > > For example, I would like to automatically get all columns from > table.c, and iterate over a record printing its fields. However when I > come across a FK field, I would like to instead of printing out the > integer value, query the database and print out the value from the > referenced record. > > The key problem is I am getting my columns from table.c, so I don't > know about the class mapper relationships that are defined. > > -- > Thadeus > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.