批量插入数据 bulk_create # 1.往书籍表中插入数据 1000 # for i in range(1000): # 这种插入方式 效率极低 # models.Book.objects.create(title='第%s本书'%i) book_list = [] for i in range(100000): # 时间还是很短 两者差距很大 book_list.append(models.Book(title='第%s本书'%i)) models.Book.objects.bulk_c…
批量插入数据 后端: def fenye(request): book_list=[] for i in range(100): book_list.append(models.Book(title='第%s本书'%i)) models.Book.objects.bulk_create(book_list) book_qurery=models.Book.objects.all() return render(request,'fenye.html',locals()) 前端: {% for b…