_post_ids _id def gen_document global _post_ids _id if _id doc_type is

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
_post_ids = []
_id = 1
def gen_document():
global _post_ids, _id
if _id == 1:
doc_type, is_o2m = 'post', 0
else:
doc_type, is_o2m = choice([('post', 0), ('comment', 1), ('revision', 1)])
doc = {'_id': str(_id), 'type': doc_type}
if is_o2m:
doc.update({'post_id': str(choice(_post_ids))})
else:
_post_ids.append(_id)
_id += 1
return doc