I'm currently working on a dashboard project to display data from multiple stats sources. I am utilizing Django along with Google Charts for creating visually appealing graphs. While the process has been smooth so far, I have hit a roadblock in one specific scenario.
The model class looks like this-
class Registration(models.Model):
event_type = models.CharField(max_length=80)
date_time = models.DateField()
count = models.IntegerField()
The query in question is-
Registration.objects.filter(event_type__in=['VHRAssmntCompleted',
'VNAAssmntCompleted',
'NonsmokersDeclrtn',
'MWBAssmntCompleted',
'VHCAssmntCompleted',
'SV Document Uploads',
'PapSmear',
'Mammogram',],
date_time__range=(d3,d1)).order_by('date_time')
The current format of the retrieved data is as shown below:
[["VHR", "2019-02-1", 23],
["VNA", "2019-02-1", 34],
["PAP", "2019-02-1", 50],
["VHR", "2019-02-2", 92],
["VNA", "2019-02-2", 13],
["PAP", "2019-02-2", 65],
["VHR", "2019-02-3", 192],
["VNA", "2019-02-3", 43],
["PAP", "2019-02-3", 11]]
In order to create a Combo Chart, I need the data to be structured as follows (similar to a Python dataframe):
[["date", "VHR", "VNA", "PAP" ],
["2019-02-1", 23,34,50],
["2019-02-2", 92,13,65],
["2019-02-3", 192,43,11]]
I am struggling to figure out a method to achieve this goal, whether it's through formatting within the Django ORM query itself or converting using JavaScript.
If anyone could provide guidance on the best approach to take, it would be greatly appreciated.