On Mon, Mar 30, 2015 at 1:09 PM, uralbash <svintso...@gmail.com> wrote: > Hello, > > I want to set up in each session was my custom attribute, for example: > > from sqlalchemy.orm import scoped_session, sessionmaker > > Session = my_wapper(scoped_session(sessionmaker())) > session1 = Session() > session2 = Session() > > hasattr(session1, foo) # True: What I want > hasattr(session2, foo) # True: What I want > print(session1.foo) > > What is the best way to do it? I have no idea how I can change the object > from __call__ function. I also did not find that something like > Session.set_property. >
You can define a subclass of the sqlalchemy Session, and ask sessionmaker to return instances of that class by passing the "class_" parameter to sessionmaker(): http://docs.sqlalchemy.org/en/rel_0_9/orm/session_api.html#session-and-sessionmaker Would that do what you wanted? Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.