class Topic(db.Model):
count_comments = db.IntegerProperty(default=0)
class Comment(db.Model):
topic = db.ReferenceProperty(Topic)
class Flag(db.Model):
pass
def txn():
comment = Comment(topic=topic)
comment.put()
add_task(..., transactional=True)
db.run_in_transaction(txn)
def txn():
flag_key_name = str(comment_key) + task_id
if Flag.get_by_key_name(flag_key_name, parent=comment_key):
return # already exceeded
comment = Comment.get(comment_key)
comment.count_comments += 1
comment.put()
flag = Flag(key_name=flag_key_name, parent=comment_key)
flag.put()
db.run_in_transaction(txn)
0 件のコメント:
コメントを投稿