Django Add object Count и Raw SQL в Javascript
def dashboard(request):
employee = Employee.objects.count()
position1 = Posit.objects.raw('SELECT employee.stat, count(posit.position_id) as NO FROM employee, posit WHERE employee.id = posit.employee_id AND posit.position_id="1" GROUP BY employee.stat')
context = {
'employee ': employee ,
'position1': [pos for pos in position1] ,
}
return render(request, 'dashboard/dashboard.html', context)
Я могу использовать подсчет сотрудников внутри javascript. var x = JSON.parse("{{employee}}")
. Как мне добавить позицию1 в переменную в javascript.
Потому что когда я добавляю var y = JSON.parse("{% for pos in position1 %}{{pos.NO}}{% endfor %}")
.
Я получил эту ошибку
Invalid block tag on line 96: 'endblock', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
Вот вся ошибка
86
87 }
88 }
89 };
90 window.onload = function () {
91 window.myRadar = new Chart(document.getElementById("canvas"), config);
92 };
93 var colorNames = Object.keys(window.chartColors);
94 </script>
95
96 {% endblock %}
97 {% block content %}
Необходимо оставить пробел между фигурными скобками:
{{ pos.NO }}