[BangPypers] SQLAlchemy and 'non-trivial' default values for a column
jace at pobox.com
Mon Feb 18 09:59:47 CET 2013
Sriram, I just noticed this thread. What you are seeking is fairly trivial once you figure out SQLAlchemy a little better.
Here is how I implemented container-unique incrementing ids:
The trick is to override __init__ and set the value of the column to an SQL expression that is evaluated database-side on commit. In my case, I'm checking for the max value from existing instances that share the same parent. In your case, it'll be instances that share the same date.
On Tuesday, 12 February 2013 at 2:02 PM, Sriram Karra wrote:
> On Tue, Feb 12, 2013 at 12:32 PM, Dhruv Baldawa <dhruvbaldawa at gmail.com (mailto:dhruvbaldawa at gmail.com)>wrote:
> > Then I guess you are doing it the wrong way. You should only have a single
> > session object (unless working with multiple databases simultaneously). The
> > object should be binded with whatever connection is required.
> I do have two separate databases - a demo database for training purposes
> and a live production database. Both have to be functional and available
> Anyway, thanks for your help. I was only trying to figure out some way of
> achieving what I wanted without accessing the session object. I guess
> that's not possible. Good to know that.
> BangPypers mailing list
> BangPypers at python.org (mailto:BangPypers at python.org)
More information about the BangPypers