Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-03 Thread Brian Findlay
Ok, Mike. Thanks. Ended up removing the trigger from the model and pushing that code to the controller, so that foo updates the bar attribute after form data with UserCourse objects is handled. On Wednesday, July 2, 2014 9:42:11 PM UTC-4, Michael Bayer wrote: On 7/2/14, 2:59 PM, Brian

[sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Brian Findlay
Hi Mike (et al.), I'm searching for a way to achieve defaultdict-like functionality for association proxies, so that a function that refers to a collection (or key within that collection) before it exists can create the collection/key with a default value. In a previous post

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Mike Bayer
On 7/2/14, 11:15 AM, Brian Findlay wrote: I've since added an event listener to perform a calculation each time a UserCourse object is set: # Recalculate 'bar' after updating UserCourse @event.listens_for(UserCourse.grade, 'set') def foo(target, value, oldvalue, initiator): courses =

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Brian Findlay
Mike, thanks for the response. (1) foo updates a particular User attribute based on a calculation performed on the user.courses collection. I'm listening for the set event on UserCourse objects to trigger foo to update that User attribute, but that isn't working with new users because -- as

Re: [sqlalchemy] defaultdict functionality for association proxies

2014-07-02 Thread Mike Bayer
On 7/2/14, 2:59 PM, Brian Findlay wrote: Mike, thanks for the response. (1) foo updates a particular User attribute based on a calculation performed on the user.courses collection. I'm listening for the set event on UserCourse objects to trigger foo to update that User attribute, but that