generate reports (excel or pdf) django

0

hello good I want to generate some type of report from the results that my searches generate, all this of a web project in django,

here my views:

What would be the easiest way to generate these reports ?, Thanks in advance.

    
asked by J Irenicus 14.08.2018 в 18:40
source

1 answer

0

You can use dataTables I leave you the link: link and an example of how you can integrate it to your template

Your js file

$(document).ready(function() {
   $('#resultadosBusqueda').dataTable({
    dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    }
   });
  });

your template

{% if query %} /*Tu context o diccionario que retorna tu consulta*/



/*id="resultadosBusqueda" lo llamas en tu .js*/
            <table id="resultadosBusqueda" class="display nowrap " cellspacing="100" width="auto">

             <thead>
                <tr>
                  <tr>
                    <th> Folio</th>
                    <th> Nombre </th>
                    <th> Edad </th>
                    <th> Genero</th>
                  </tr>
                </tr>
             </thead>

            <tbody>
      {% for item in query %}



                <tr>

                    <td><br>{{ item.folio }}</td>
                    <td><br>{{ item.nombre}</td>
                    <td><br>{{ item.edad}}</td>
                    <td >
                        {{ item.genero}}</a>

                    </td>
                </tr>

      {% endfor %}
        {% else %}
                <br>
                <br>

        {% endif %}
            </tbody>

            </table>
    
answered by 15.08.2018 / 01:13
source