You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-8
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,14 @@
4
4
5
5
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/)
6
6
7
-
The package contains one function named "generateFromSql" accepting 12 arguments :
7
+
The package contains two functions named:
8
+
-**generate_from_sql**: Generate HTML table by given SQL query
9
+
-**generate_from_queryset**:Generate HTML table by given Django queryset
10
+
11
+
Parameters:
8
12
9
-
* cursor : DB cursor
10
13
* title : The title of the report that will be shown on top of table
11
-
* sqltext : The sql select query to retrieve data
14
+
* sqltext/queryset : The sql select query to retrieve data / django queryset
12
15
* footerCols : A list of columns name that you want to have Sum of values on footer . Example : ['amount','price']
13
16
* htmlClass : Html CSS classes for the table
14
17
* direction (default = "ltr") : Indicates direction of the report page. "ltr"- Left to Right , "rtl" - Right to Left
@@ -28,17 +31,16 @@ Run following command to install DjangoQtt :
28
31
pip install django-query-to-table
29
32
```
30
33
31
-
## Usage :
34
+
## Example usage :
32
35
36
+
- Generate HTML table by SQL query:
33
37
34
38
```python
35
-
from django.db import connection
36
39
from django_query_to_table import DjangoQtt
37
40
from django.http import HttpResponse
38
41
39
42
# view function in Django project
40
43
deflistOfPersons(request):
41
-
cursor = connection.cursor()
42
44
reportTitle ="Employee List"
43
45
sqlQuery ="SELECT FirstName as 'First Name', LastName as 'Last Name', phone as 'Phone Number', salary as 'Salary' FROM persons"
" <tr style='background-color:{{headerRowColor}}'>{% if rowIndex %} <th align=\"center\"> # </th> {% endif %} {% for c in columns %} <th>{{ c }}</th> {% endfor %} </tr> </thead>"
51
+
" <tbody> {% for d in data %} <tr style='background-color:{% if forloop.counter0|divisibleby:'2' %} {{evenRowColor}} {% else %} {{oddRowColor}} {% endif %} ' >"
52
+
" {% if rowIndex %} <td align=\"center\">{{ forloop.counter }}</td> {% endif %} {% for attr, value in d.items %} <td align=\"center\">{{ value }}</td> {% endfor %} </tr> {% endfor %} "
53
+
" {% if sumOfColumn %} <tr style='background-color:#eee;font-weight: bold;'> <td></td> {% for a,v in sumOfColumn.items %} <td align=\"center\">{{ v }}</td> {% endfor %} </tr> {% endif %}</tbody> </table></center>"
0 commit comments