我有一个用下面的Chart JS库创建的图表:
我的Models.py如下:
class Organization(models.Model):
name = models.CharField(max_length=250, unique=True)
def __str__(self):
return self.name
class AppealForm(models.Model):
form_name = models.CharField(max_length=100)
def __str__(self):
return self.report_form_name
class Appeal(models.Model):
organization = models.ForeignKey(Organization, on_delete=models.SET_NULL, blank=True, null=True)
appeal_form = models.ForeignKey(AppealForm, on_delete=models.CASCADE, blank=True, null=True)
appeal_number = models.CharField(max_length=100, blank=True, null=True)
applicant_first_name = models.CharField(max_length=100, blank=True, null=True)
applicant_second_name = models.CharField(max_length=100, blank=True, null=True)
date = models.DateField(blank=True, null=True)
appeal_body = models.TextField()
用于创建精选折线图的Chart JS脚本:
new Chart(chartTwo, {
type: 'line',
data: {
labels: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'],
datasets: [
{
label: 'written',
data: [
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
],
borderColor: "green",
backgroundColor: "green",
},
{
label: 'oral',
data: [
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
Math.floor(Math.random() * 100),
],
borderColor: "blue",
backgroundColor: "blue",
},
]
},
options: {
responsive: true,
scales: {
y: {
min: -20,
max: 120,
}
}
},
})
Qestion:,how the query will look like for this graph using AppealForm model?.
附注:我想要从年初到年底逐月统计每个外观表单模型对象的数量.今年还没有结束,所以在这个月剩下的时间里,我希望获得0值以响应地粘贴到图表中.
=
更新:
组织模型的对象:
# | name |
---|---|
1 | Apple |
2 | Samsung |
外观模型的对象:
# | form_name |
---|---|
1 | written |
2 | oral |
上诉对象模式:
there are more appeals to show here, but it does not play a role in the query I want个
更新问题:如何查询OualForm(specalForm.objects.et...)表以获取上述折线图的数据?