[![Downloads](https://static.pepy.tech/personalized-badge/django-query-to-table?period=total&units=international_system&left_color=black&right_color=green&left_text=Downloads)](https://pepy.tech/project/django-query-to-table)
### django-query-to-table (DjangoQtt) is an easy to use django package to generate html table from sql query.
You can read more about this package here : [django query to table package](https://mshaeri.com/blog/generate-html-table-report-from-sql-query-in-django/)
The package contains two functions named:
- **generate_from_sql**: Generate HTML table by given SQL query
- **generate_from_queryset**:Generate HTML table by given Django queryset
Parameters:
* 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 :
```shell
pip install django-query-to-table
```
## Example usage :
- Generate HTML table by SQL query:
```python
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:
```python
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.all().values("customer", "product", "amount")
reportTitle = "Order List"
columnsToBeSummarized = ['amount']
fontName = "Arial"
cssClasses = "reportTable container"
headerRowBackgroundColor = '#ffeeee'
evenRowsBackgroundColor = '#ffeeff'
oddRowsBackgroundColor = '#ffffff'
rowIndexVisibility = True
table = DjangoQtt.generate_from_queryset(reportTitle, order_queryset, columnsToBeSummarized, cssClasses,
"ltr", fontName, "Total amount", rowIndexVisibility,
headerRowBackgroundColor, evenRowsBackgroundColor, oddRowsBackgroundColor
)
# here the table is a string variable containing the html table showing the queryset result
return HttpResponse(table)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/birddevelper/django-query-to-table",
"name": "django-query-to-table",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "Django, Report, HTML, Table, SQL",
"author": "M.Shaeri",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c2/4b/ea983cd498406fd6a38ce0578add5cd6ed5911e61b3faba9da5274aaab72/django_query_to_table-1.0.0.tar.gz",
"platform": null,
"description": "[![Downloads](https://static.pepy.tech/personalized-badge/django-query-to-table?period=total&units=international_system&left_color=black&right_color=green&left_text=Downloads)](https://pepy.tech/project/django-query-to-table)\n\n### django-query-to-table (DjangoQtt) is an easy to use django package to generate html table from sql query.\n\nYou can read more about this package here : [django query to table package](https://mshaeri.com/blog/generate-html-table-report-from-sql-query-in-django/)\n\nThe package contains two functions named:\n- **generate_from_sql**: Generate HTML table by given SQL query\n- **generate_from_queryset**:Generate HTML table by given Django queryset\n\nParameters:\n\n* title : The title of the report that will be shown on top of table\n* sqltext/queryset : The sql select query to retrieve data / django queryset\n* footerCols : A list of columns name that you want to have Sum of values on footer . Example : ['amount','price']\n* htmlClass : Html CSS classes for the table\n* direction (default = \"ltr\") : Indicates direction of the report page. \"ltr\"- Left to Right , \"rtl\" - Right to Left\n* font (default = \"Tahoma\") : Font of title and table contents\n* totalText (default = \"Total\") : Title of footer row that will be the put below the first column.\n* rowIndex (default = False) : Indicates whether the table should have index column or not.\n* headerRowColor (default = '#eeeeee') : The header (title) row background color.\n* evenRowColor (default = '#ffffff') : The even rows background color.\n* oddRowColor (default = '#ffffff') : The odd rows background color.\n\n\n\n## Installation\nRun following command to install DjangoQtt :\n\n```shell\npip install django-query-to-table\n```\n\n## Example usage :\n\n- Generate HTML table by SQL query:\n\n```python\nfrom django_query_to_table import DjangoQtt\nfrom django.http import HttpResponse\n\n# view function in Django project\ndef listOfPersons(request):\n reportTitle = \"Employee List\"\n sqlQuery = \"SELECT FirstName as 'First Name', LastName as 'Last Name', phone as 'Phone Number', salary as 'Salary' FROM persons\"\n columnsToBeSummarized = ['Salary']\n fontName = \"Arial\"\n cssClasses = \"reportTable container\"\n headerRowBackgroundColor = '#ffeeee'\n evenRowsBackgroundColor = '#ffeeff'\n oddRowsBackgroundColor = '#ffffff'\n rowIndexVisibility = True\n table = DjangoQtt.generate_from_sql(reportTitle, sqlQuery, columnsToBeSummarized, cssClasses,\n \"ltr\", fontName, \"Total Salary\", rowIndexVisibility,\n headerRowBackgroundColor, evenRowsBackgroundColor, oddRowsBackgroundColor\n )\n \n # here the table is a string variable containing the html table showing the query result\n return HttpResponse(table)\n \n ```\n\n- Generate HTML table from querset:\n\n```python\nfrom django_query_to_table import DjangoQtt\nfrom django.http import HttpResponse\nfrom .models import Order\n# view function in Django project\ndef listOfPersons(request):\n\n order_queryset = Order.objects.all().values(\"customer\", \"product\", \"amount\")\n reportTitle = \"Order List\"\n columnsToBeSummarized = ['amount']\n fontName = \"Arial\"\n cssClasses = \"reportTable container\"\n headerRowBackgroundColor = '#ffeeee'\n evenRowsBackgroundColor = '#ffeeff'\n oddRowsBackgroundColor = '#ffffff'\n rowIndexVisibility = True\n table = DjangoQtt.generate_from_queryset(reportTitle, order_queryset, columnsToBeSummarized, cssClasses,\n \"ltr\", fontName, \"Total amount\", rowIndexVisibility,\n headerRowBackgroundColor, evenRowsBackgroundColor, oddRowsBackgroundColor\n )\n \n # here the table is a string variable containing the html table showing the queryset result\n return HttpResponse(table)\n \n ```\n",
"bugtrack_url": null,
"license": "GNU",
"summary": "A simple to use Django package to turn your queryset and sql query into a beautiful reporting html table",
"version": "1.0.0",
"project_urls": {
"Download": "https://pypi.org/project/django-query-to-table/",
"Homepage": "https://github.com/birddevelper/django-query-to-table"
},
"split_keywords": [
"django",
" report",
" html",
" table",
" sql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "64c54a05abb18001230c373f85aa9ba0179502bc35f4ae9bc7b9a682bc8a15a2",
"md5": "bffdf00c3a817087e100edbaa1442f93",
"sha256": "4fd3bbfd8570939ccc129ca496f1e14be75a9e0834a4b3e2dbe1642d295e0a6c"
},
"downloads": -1,
"filename": "django_query_to_table-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bffdf00c3a817087e100edbaa1442f93",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4787,
"upload_time": "2024-12-14T19:01:12",
"upload_time_iso_8601": "2024-12-14T19:01:12.432457Z",
"url": "https://files.pythonhosted.org/packages/64/c5/4a05abb18001230c373f85aa9ba0179502bc35f4ae9bc7b9a682bc8a15a2/django_query_to_table-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c24bea983cd498406fd6a38ce0578add5cd6ed5911e61b3faba9da5274aaab72",
"md5": "c8e3c2adb9667b3f8a4b4aeb1d636bf6",
"sha256": "7802fe007d2f80bc189bf1287b9bec1d0d3edd721c016e0679dbf0db93387c6a"
},
"downloads": -1,
"filename": "django_query_to_table-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "c8e3c2adb9667b3f8a4b4aeb1d636bf6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4274,
"upload_time": "2024-12-14T19:01:13",
"upload_time_iso_8601": "2024-12-14T19:01:13.407019Z",
"url": "https://files.pythonhosted.org/packages/c2/4b/ea983cd498406fd6a38ce0578add5cd6ed5911e61b3faba9da5274aaab72/django_query_to_table-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-14 19:01:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "birddevelper",
"github_project": "django-query-to-table",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-query-to-table"
}