-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathseed.py
More file actions
57 lines (46 loc) · 1.27 KB
/
seed.py
File metadata and controls
57 lines (46 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
seed
~~~~
Add a lot of content to the forum.
:license: MIT and BSD
"""
import random
from application import db
from application.models import *
NUM_BOARDS = 1
NUM_THREADS = 100
NUM_POSTS = 20
def main():
users = User.query.all()
Board.query.delete()
Thread.query.delete()
Post.query.delete()
for b in range(NUM_BOARDS):
board = Board(
name='Board %s' % b,
slug='board-%s' % b,
description='This is board number %s.' % b
)
db.session.add(board)
db.session.flush()
for t in range(NUM_THREADS):
author_id = random.choice(users).id
thread = Thread(
name='Thread %s' % t,
author_id=author_id,
board_id=board.id
)
db.session.add(thread)
db.session.flush()
for p in range(NUM_POSTS):
author_id = random.choice(users).id
post = Post(
content='This is post number %s.' % p,
author_id=author_id,
thread_id=thread.id
)
thread.posts.append(post)
db.session.commit()
if __name__ == '__main__':
main()