显示Django模板表

时间:2018-09-24 03:32:05

标签: django django-queryset

我目前定义了4个表:

 station(models.Model):
    station_name=models.CharField()

 data1(models.Model):
    station = models.ForeignKey(station)
    date = models.DateField()
    value1 = models.CharField()

 data2(models.Model):
    station = models.ForeignKey(station)
    date = models.DateField()
    value2 = models.CharField()
    value3 = models.CharField()


 data3(models.Model):
    station = models.ForeignKey(station)
    date = models.DateField()
    value4 = models.CharField()
    value5 = models.CharField()

我目前还具有以下查询集:

mydate = '2018-09-09'
data_1 = data1.objects.filter(date__gte= mydate )
<Queryset[<data1 : 2018-09-19>,<data1 : 2018-09-19>,<data1: 2018-09-20>]
data_2 = data1.objects.filter(date__gte= mydate )
<Queryset[<data2 : 2018-09-19>,<data2 : 2018-09-19>,<data2: 2018-09-22>,<data2: 2018-09-23>]
data_3 = data1.objects.filter(date__gte= mydate )
<Queryset[<data3 : 2018-09-19>,<data3 : 2018-09-19>,<data3: 2018-09-22>]

如何创建类似于以下内容的html表:

  station | date      | value1 | value2 | value3 | value4 | value5
  1       | 2018-09-19|  x1    |  y1    | z1     | a1     | b1
  2       | 2018-09-19|  x2    |  y2    | z2     | a2     | b2
  1       | 2018-09-20|  x3    |  Null  | Null   | Null   | Null
  2       | 2018-09-22|  NUll  |  y4    | z4     | a4     | b4
  1       | 2018-09-23|  NUll  |  y5    | z5     | Null   | Null

谢谢您的帮助

0 个答案:

没有答案