This is brett's Typepad Profile.
Join Typepad and start following brett's activity
Join Now!
Already a member? Sign In
brett
Recent Activity
Use a piece of this to define sync() for yourself, and you should be good to go. Just make sure to do sync() after the transaction finishes (using a closure, or something): class MyModel(db.Model): foo = db.IntegerProperty(default=0) def add_one(self): python_scoping_is_annoying = [None] def txn(): new = python_scoping_is_annoying[0] = db.get(self.key()) new.foo += 1 new.put() db.run_in_transaction(txn) new = python_scoping_is_annoying[0] # Copy all new values over to this instance. for k in new.properties().keys() + new.dynamic_properties(): setattr(self, k, getattr(new, k)) a = MyModel() a.put() print a.key(), a.foo a.add_one() print a.key(), a.foo a.add_one() print a.key(), a.foo Output: agVzaGVsbHIPCxIHTXlNb2RlbBjKqwUM 0 agVzaGVsbHIPCxIHTXlNb2RlbBjKqwUM 1 agVzaGVsbHIPCxIHTXlNb2RlbBjKqwUM 2
1 reply