Skip to content

Instantly share code, notes, and snippets.

@afrinjamanbd
Created December 2, 2021 15:11
Show Gist options
  • Save afrinjamanbd/f81f3d0b15b7cecd3bf8db94a8375922 to your computer and use it in GitHub Desktop.
Save afrinjamanbd/f81f3d0b15b7cecd3bf8db94a8375922 to your computer and use it in GitHub Desktop.
Simple example to use gviz_api with Django Models
import gviz_api
description = {"name": ("string", "Name"),
"salary": ("number", "Salary"),
"full_time": ("boolean", "Full Time Employee")}
data = [{"name": "Mike", "salary": (10000, "$10,000"), "full_time": True},
{"name": "Jim", "salary": (800, "$800"), "full_time": False},
{"name": "Alice", "salary": (12500, "$12,500"), "full_time": True},
{"name": "Bob", "salary": (7000, "$7,000"), "full_time": True}]
data_table = gviz_api.DataTable(description)
data_table.LoadData(data)
print("Content-type: text/plain")
print()
jsonData = data_table.ToJSon(columns_order=("name", "salary", "full_time"),
order_by="salary")
print(data_table.ToJSonResponse(columns_order=("name", "salary", "full_time"),
order_by="salary"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment