[Python] How can I display a table in a template with additional category/section rows?

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    Have a nice day!

    I have a non-standard table. Which I plan to display in the template.

    I load the table into the template from the model. And I have additional sections - additional fields. These additional fields characterize - Category, Section, Topics. I am thinking how to display such a table from the model in the template - as shown in the image below.

    [​IMG]

    To additionally implement additional fields - categories or sections in the table.

    I have a rough idea -

    I have to create a transit model for exactly such a table - in which the number of rows is equal to the number of rows of the original table + plus the number of rows of category sections in addition. That is, there can be about 25 rows of the original table and + plus 6 rows - category sections. In total, the required table will have 31 rows of rows.

    But how to display them in the form as in my picture - separating categories sections?

    models.py

    class CreateNewGPR (models.Model):
    name_object = models.IntegerField(verbose_name="")
    name_category = models.CharField(verbose_name="")
    name_working = models.CharField(verbose_name="")
    type_izm = models.CharField(choices=TYPE_IZMERENIYA, verbose_name="")
    value_work = models.FloatField(verbose_name="")
    lyudi_norma = models.IntegerField(verbose_name="")
    technik_norma = models.IntegerField(verbose_name="")
    date_begin = models.DateField(verbose_name="")
    date_end = models.DateField(verbose_name="")


    views.py

    filter_qs = CreateNewGPR.objects.filter(name_object=pk)
    filter_qs = filter_qs.values("name_working", "type_izm", "value_work", "lyudi_norma", "technik_norma", "date_begin", "date_end")

    context['books'] = filter_qs


    template.html

    <div>
    <table class="pure-table">
    <thead>
    <tr>
    <th>Name Column 1</th>
    <th>Name Column 2</th>
    <th>Name Column 3</th>
    <th>Name Column 4</th>
    <th>Name Column 5</th>
    <th>Name Column 6</th>
    <th>Name Column 7</th>
    </tr>
    </thead>
    <tbody>
    {% for book in books %}
    <tr>
    <td>{{ book.name_working }}</td>
    <td>{{ book.type_izm }}</td>
    <td>{{ book.value_work }}</td>
    <td>{{ book.lyudi_norma }}</td>
    <td>{{ book.technik_norma }}</td>
    <td>{{ book.date_begin }}</td>
    <td>{{ book.date_end }}</td>
    </tr>
    {% endfor %}
    </tbody>
    </table>
    </div>

    Continue reading...

Compartilhe esta Página