Skip to main content

Downloads

django-query-to-table (DjangoQtt) is an easy to use django package to generate html table from django queryset or sql query.

You can read more about this package here : django query to table package

The package has two functions, named:

  • generate_from_sql: Generate HTML table by given SQL query
  • generate_from_queryset:Generate HTML table by given Django queryset

Parameters and options:

  • title : The title of the report that will be shown on top of table
  • sqltext/queryset : The sql select query to retrieve data / django queryset
  • footerCols : A list of columns name that you want to have Sum of values on footer . Example : ['amount','price']
  • htmlClass : Html CSS classes for the table
  • direction (default = "ltr") : Indicates direction of the report page. "ltr"- Left to Right , "rtl" - Right to Left
  • font (default = "Tahoma") : Font of title and table contents
  • totalText (default = "Total") : Title of footer row that will be the put below the first column.
  • rowIndex (default = False) : Indicates whether the table should have index column or not.
  • headerRowColor (default = '#eeeeee') : The header (title) row background color.
  • evenRowColor (default = '#ffffff') : The even rows background color.
  • oddRowColor (default = '#ffffff') : The odd rows background color.

Installation

Run following command to install DjangoQtt :

pip install django-query-to-table

Example usage :

  • Generate HTML table by SQL query:
from django_query_to_table import DjangoQtt
from django.http import HttpResponse

# view function in Django project
def listOfPersons(request):
  reportTitle = "Employee List"
  sqlQuery = "SELECT FirstName as 'First Name', LastName as 'Last Name', phone as 'Phone Number', salary as 'Salary' FROM persons"
  columnsToBeSummarized = ['Salary']
  fontName = "Arial"
  cssClasses = "reportTable container"
  headerRowBackgroundColor = '#ffeeee'
  evenRowsBackgroundColor = '#ffeeff'
  oddRowsBackgroundColor = '#ffffff'
  rowIndexVisibility = True
  table = DjangoQtt.generate_from_sql(reportTitle, sqlQuery, columnsToBeSummarized, cssClasses,
                                  "ltr", fontName, "Total Salary", rowIndexVisibility,
                                  headerRowBackgroundColor, evenRowsBackgroundColor, oddRowsBackgroundColor
                                  )
  
  # here the table is a string variable containing the html table showing the query result
  return HttpResponse(table)
   
  • Generate HTML table from querset:

Since Django 4.0.4 introduced a security fix that disallows spaces in aliases, you can use double underscores (__) as a substitute in your aliases. The table generator will automatically display them as spaces in the output. Here's an example:

from django_query_to_table import DjangoQtt
from django.http import HttpResponse
from .models import Order
# view function in Django project
def listOfPersons(request):

  order_queryset = Order.objects.annotate(
      **{
         'Order__Number': F('order_number'),
         'Order__Item': F('order_item'),
         'Customer__Name': F('customer_name'),
         'Order__Date': F('order_date'),
         'Total__Amount': F('total_amount'),
      }
   ).values(
      'Order__Number',
      'Order__Item',
      'Customer__Name',
      'Order__Date',
      'Total__Amount'
   )

  table = DjangoQtt.generate_from_queryset(
                                       title = "Summmary Table",
                                       queryset = order_queryset,
                                       htmlClass = "summary",
                                       rowIndex = True,
                                       footerCols=['Total__Amount'],

                                    )
  
  return HttpResponse(table)
   

The table will be look like this:

table

If you find this package useful, please consider giving it a star! ⭐ It helps support the project and lets others discover it.

Metadata

Release files for django-query-to-table 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-query-to-table 1.1.1
File Size Uploaded
django_query_to_table-1.1.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-query-to-table 1.1.1
File Interpreter ABI Platform
django_query_to_table-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / django_query_to_table-1.1.1.tar.gz

Download URL django_query_to_table-1.1.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
96a5480de1d024eb9b5a43ae38aa46120a46ca9315a234783fff0ec90c5cfaff
BLAKE2b-256 checksum
How to use checksums
9d6e8e923954705694cdfeca50e92004c4ed07b9486fc1d7110a0a54e6106c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / django_query_to_table-1.1.1-py3-none-any.whl

Download URL django_query_to_table-1.1.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36227e96da3afbd685a474521dc13f93f83cff49fbcf9bdef16c513ab31f8775
BLAKE2b-256 checksum
How to use checksums
1856bc0c043aa735baf72c10ada35d40ed180dbef6ef61ce76911b6f5b9f40a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page