It’s time to move up from the usual for element on queryset:
to build my context for template.
Need some help with it, either the python side or html template need some modification just don’t know how.
Inventory list have 1000’s of serial numbers, once a employe take x amount equipment a transaction record created. Record hold ‘created_at, employee_id, euq_id’, there is many equipment type.
Current queryset return count of each equipment type count but they way its packed I cant unpack it in the template for chart.js
report = cpeTransaction.objects.filter(emp=130).values('equ__cpe') \
.annotate(total=Count('equ__cpe', distinct=False)) \
.values_list("equ__cpe__name", "total")
return render(request, 'inventory/report.html',
{'result': list(report)})
this yield close to what i want but not exactly.
labels: [('XB6', 4), ('XONE', 1), ('XI6', 1), ('XG1V3', 1)],
data: [('XB6', 4), ('XONE', 1), ('XI6', 1), ('XG1V3', 1)],
desired output would be
labels: ['XB6', 'XONE', 'XI6', 'XG1V3'],
data: [(4, 1, 1, 1],
data: {
labels: {{ result|safe }},
datasets: [
{
data: {{ result|safe }},
borderColor:' #589239',
backgroundColor: '#9bff64cc',
borderWidth: 2,
borderRadius: 10,
borderSkipped: false,
label: 'Employee Name'
}],
},
any suggestion how to return list instead of list of list ?