title: running transactions in db.Model subclassed put
body: <p>I'm trying to create a google app engine data model with the following attributes:</p>
  
  <ol>
  <li>store string, value pair into BigTable</li>
  <li>if string, value pair DOES NOT exist, create the record</li>
  <li>if string, value pair DOES exist, update the record, incrementing a counter</li>
  </ol>
  
  <p>code:</p>
  
  <pre><code>class stringListRecord(db.Model):
      type  = db.StringProperty();
      value = db.StringProperty();
      refs  = db.IntegerProperty(default=1);
  
      def __init__(self, *args, **kw):
          key = db.GqlQuery("SELECT __key__ FROM stringListRecord WHERE type = :1 AND value = :2", kw['type'], kw['value']).get();
          if key != None:
              kw['key'] = key;
          db.Model.__init__(self, *args, **kw);
  
      def increment_counter(self, key):
          obj = db.get(key);
          obj.refs += 1;
          db.Model.put(obj);
  
      def put(self):
          if self.key() != None:
              self.increment_counter(self.key());
              #db.run_in_transaction(self.increment_counter, self.key());
          else:
              db.Model.put(self);
  </code></pre>
  
  <p>When I run the commented out code, i.e. db.run_in_transaction() I get:</p>
  
  <pre><code>Only ancestor queries are allowed inside transactions.
  </code></pre>
  
  <p>Is there a better way to get this functionality out of GAE?</p>