On 5/23/11 12:23 , neurino wrote:
 > Creating tables and adding initial content is better done with paster
setup-app or another separate command.

But setup-app is not present in pyramid.

setup-app is a PasteDeploy thing. You can use it with pyramid apps if you want to, but I would recommend using a paster command approach instead: much simpler and does not suffer from the many problems setup-app has.

I understand your point and I'm also going, in production, to move that
code in a setup script.

Anyway then, having:

     import transaction

at the top of my models.py what do I have to take care when adding,
merging or removing content?

Personally I use a repoze.tm2 middleware to manage all my transactions. That makes everything Just Work, and you never have to worry about transactions again. I know other people prefer a more pyramid-specific approach of using Pyramid events to manage transactions.

And, back to my initial question:

in Pylons I had a Session instance named "session" i used in my
controllers like

     model.session.add(anything)
     model.session.commit()

what I'm supposed to do now?

     models.DBSession().add(anything)

That is the exact same thing. DBSession is just a SQLAlchemy ScopedSession object, same as your model.session object in a Pylons 1 project. You can use model.DBSession.add as well - SQLAlchemy will
do the same thing.


I'm not used to instantiate & call "Class().method" that much and looks
me ugly but if it's the correct way to go with it...

If you do 'model.session.add' SQLAlchemy will internally do the same thing: it finds the current session for your thread and runs add on it.

Wichert.

--
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to