bulk_create bulk insert data

DEF booklist (Request):
     # dynamically inserting data 100 
    for I in Range (100 ): 
        models.Book2.objects.create (name = ' % s of the book ' % I)
     # bulk insert data 
    L = []
     for I in Range (10000 ): 
        l.append (models.Book2 (name = ' % s of the book ' % I)) 
    models.Book2.objects.bulk_create (L)

Front-end code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
   <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <table class="table table-hover table-bordered table-striped">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>name</th>
                    </tr>
                </thead>
                <tbody>
                    {% for book in page_queryset %}
                    <tr>
                        <td>{{ book.pk }}</td>
                        <td>{{ book.name }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>

            {{ page_obj.page_html|safe }}

        </div>
    </div>
</div>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/HUIWANG/p/11033044.html