Christoph Haas wrote: > Dear list, > > I used to use a certain ORM base class with SQLA 0.4 for a while. It > defined __init__, __repr__ and update so that I could preset mapped > objects with values like > > leo = User(name='leo', age=23) > > or just > > print leo > > and especially > > leo.update(dictionary_from_web_form) > > I couldn't find it on the wiki anymore. And what I use here doesn't work > properly on 0.5 (it relies heavily on the 'c' attribute and just removing > it doesn't solve things because it tries "if a_certain_attribute in > this_object.c"). > > If anyone has "ported" that few lines of code to 0.5 please let me know. > > I thought that the declarative_base helps here but it's just helping with > the declaration. > > Cheers > Christoph > I asked a similar question a long time ago and have the following based on code proposed by Michael Bayer at the time.
class BaseExt(object): def __repr__(self): return "%s(%s)" % ( (self.__class__.__name__), ', '.join(["%s=%r" % (key, getattr(self, key)) for key in sorted(self.__dict__.keys()) if not key.startswith('_')])) Base = sad.declarative_base(cls=BaseExt) metadata = Base.metadata class Language(Base): __table__ = sa.Table(u'language', metadata, sa.Column(u'langid', sa.Integer(), sa.Sequence('gen_language_langid'), primary_key=True, nullable=False), sa.Column(u'name', sa.String(length=50, convert_unicode=False), nullable=False), etc etc item = db.Language(name='something') print item Werner --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---