def create_db(): try: User.drop_table() Member.drop_table() Commodity.drop_table() Category.drop_table() UserOrder.drop_table() OrderItem.drop_table() CommodityImage.drop_table() CommodityComment.drop_table() Address.drop_table() OrderStatus.drop_table() Announcement.drop_table() Feedback.drop_table() except: pass User.create_table() Member.create_table() Commodity.create_table() Category.create_table() UserOrder.create_table() OrderItem.create_table() CommodityImage.create_table() CommodityComment.create_table() Address.create_table() OrderStatus.create_table() Announcement.create_table() Feedback.create_table()
def init_db(): # init status global status_list global memberships global category_list global user_list s_init = OrderStatus.create(name="init") s_confirmed = OrderStatus.create(name="confirmed") s_sent = OrderStatus.create(name="sent") s_complete = OrderStatus.create(name="complete") s_canceled = OrderStatus.create(name="canceled") status_list += [s_init, s_confirmed, s_sent, s_complete, s_canceled] member0 = Member.create(name="normal", point=1000, discount=100) member1 = Member.create(name="vip1", point=2000, discount=90) member2 = Member.create(name="vip2", point=3000, discount=80) member3 = Member.create(name="vip3", point=4000, discount=70) member4 = Member.create(name="vip4", point=5000, discount=60) member5 = Member.create(name="vip5", point=-1, discount=50) memberships += [member1, member2, member3, member4] # init user User.create(username="******", password="******", admin=True) # user = User.create(username="******", password="******", admin=True) # user.set_password("zhang") # user.save() Announcement.create(title="Hello", content="World") Announcement.create(title="Hello", content="World") Announcement.create(title="Hello", content="World") for i in range(100): random_user() # init Commodity cat = Category.create(name="All") category_list.append(cat) for i in range(10): random_cat() for i in range(100): random_co() for u in user_list: random_order(u) for i in range(20): random_feed()