def init(username, password): """初始化数据库 admin 分类""" click.echo('初始化数据库中...') db.create_all() with db.auto_commit(): admin = Admin.query.first() if admin is not None: click.echo('管理员账号已存在,更新中...') admin.username = username admin.set_password(password) else: click.echo('创建默认管理员数据中...') admin = Admin( username=username, blog_title='Br Blog', blog_sub_title="Genius only means hard-working all one's life.", name='Jack Zhang', about='''永不放弃是人生要成功的一大因素, 只要能够坚持, 锲而不舍, 终会到达成功的彼岸的。''' ) admin.set_password(password) db.session.add(admin) category = Category.query.first() if category is None: click.echo('创建默认分类...') category = Category(name='Default') db.session.add(category) click.echo('Done.')
def createadmin(username, password): admin = Admin() admin.username = username admin.set_password(password) db.session.add(admin) db.session.commit() print('success!')
def fake_admin(): with db.auto_commit(): data = Admin( username='******', blog_title='Br Blog', blog_sub_title = "Genius only means hard-working all one's life.", name = 'Jack Zhang', about = '''永不放弃是人生要成功的一大因素, 只要能够坚持, 锲而不舍, 终会到达成功的彼岸的。''' ) data.set_password('adminadmin') db.session.add(data)