# 往数据库中添加数据 def books_bulk(request): book_list = [] for i in range(100,150): book = Book(title="book_%s" % i, price=i * i, pub_date="2018-11-2", publish_id=random.randint(1, 2)) book_list.append(book) print(book_list) Book.objects.bulk_create(book_list) w = Book.objects.all() for i in w: i.authors.add(random.randint(1, 2)) return redirect("/books/")