def init(): print('正在创建 权限管理 类别.....') _role = Role() _role.insert_roles() print('成功创建权限管理! \n') print('-' * 30) print('正在创建默认分类...') category = Category() print('创建成功! 分类: default, \n') print('-' * 30) print('请先设置管理员账号') email = input('请设置邮箱, 作为登录账号(email): ') username = input('请输入用户名(username): ') password = input('请输入密码(password) " 请 注 意! 明文显示": ') user = User() role = Role.query.get(3) with db.auto_commit(): category.category_name = 'default' user.email = email user.username = username user.password = password user.role = role db.session.add(user) db.session.add(category) print('创建管理员成功') print('请前往 /admin/ 下的 "类别管理" 创建 "类别" ')
def test_category_model(self): category = Category() category.category_id = '228383838' category.category_name = 'Others' db.session.rollback() db.session.add(category) self.assertEqual(None, db.session.commit())
def add_category(): category = Category() category.category_title = request.form.get('name') category.category_name = request.form.get('alias') category.category_keyword = request.form.get('keywords') category.category_describe = request.form.get('describe') category.save() return redirect(url_for('blog.category'))
def seed_categories_data(): category_ids = ('cat-1234', 'cat-1256', 'cat-3456', 'cat-5678', 'cat-3443') category_names = ('Banks', 'Hostels', 'Others', 'Administrative', 'Schools') categories_data = dict(zip(category_ids, category_names)) for id,name in categories_data.items(): category = Category() category.category_id = id category.category_name = name db.session.add(category) db.session.commit() print(category) return True