我有像
这样的模特class MyModel(models.Model):
date = models.DateField()
type = models.CharField(max_length=10)
n_1 = models.IntegerField()
n_2 = models.IntegerField()
日期是唯一的,而类型不是。 我想创建带有X轴标签的图表,如" Type(Date)" ie" FirstType(2014-10-02)",所以我想组合轴标签中两个模型字段的数据。能告诉我怎么办?
答案 0 :(得分:2)
不需要将模型对象直接传递给chartit。您可以将它们转换为具有适当值的dicts:
data = [
{'label': "{0} ({1})".format(o.date, o.type), 'value': o.n_1}
for o in MyModel.objects.all()
]
有关您选择用于获取更多信息的库,请参阅the documentation。