from flask_script import Manager app = Flask(name) basedir = os.path.abspath(os.path.dirname(file)) manager=Manager(app)
def register_commands(app): @manager.option('--drop', default=True, help='Create after drop.') def initdb(drop): """Initialize the database.""" if drop: click.confirm('This operation will delete the database, do you want to continue?', abort=True) db.drop_all() print('Drop tables.') db.create_all() Role.init_role() print('Initialized database.')
代码语言:javascript复制@manager.option('--user', default=10, help='Quantity of users, default is 10.')
@manager.option('--follow', default=30, help='Quantity of follows, default is 30.')
@manager.option('--photo', default=30, help='Quantity of photos, default is 30.')
@manager.option('--tag', default=20, help='Quantity of tags, default is 20.')
@manager.option('--collect', default=50, help='Quantity of collects, default is 50.')
@manager.option('--comment', default=100, help='Quantity of comments, default is 100.')
def forge(user, follow, photo, tag, collect, comment):
"""Generate fake data."""
from fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_tag, fake_user, fake_collect
db.drop_all()
db.create_all()
print('Initializing the roles and permissions...')
Role.init_role()
print('Generating the administrator...')
fake_admin()
print('Generating %d users...' % user)
fake_user(user)
print('Generating %d follows...' % follow)
fake_follow(follow)
print('Generating %d tags...' % tag)
fake_tag(tag)
print('Generating %d photos...' % photo)
fake_photo(photo)
print('Generating %d collects...' % photo)
fake_collect(collect)
print('Generating %d comments...' % comment)
fake_comment(comment)
print('Done.')