在Django

时间:2017-08-14 18:56:48

标签: django django-models django-views

我正在尝试根据年,月和列值对我的数据进行分组。 查询是

 FeedbackData.objects.annotate(year=ExtractYear('created'), month=ExtractMonth('created')).values('year','month','start_operator_alias').annotate(dcount=Count('*')).values('year', 'month','start_operator_alias','dcount')

我得到的结果是:

<QuerySet [{'year': None, 'start_operator_alias': 7, 'dcount': 12858, 'month': None}, {'year': None, 'start_operator_alias': 2, 'dcount': 185042, 'month': None}, {'year': None, 'start_operator_alias': 5, 'dcount': 13963, 'month': None}, {'year': None, 'start_operator_alias': 3, 'dcount': 127819, 'month': None}, {'year': None, 'start_operator_alias': 0, 'dcount': 566040, 'month': None}, {'year': None, 'start_operator_alias': 6, 'dcount': 83877, 'month': None}, {'year': None, 'start_operator_alias': 1, 'dcount': 170064, 'month': None}, {'year': None, 'start_operator_alias': -1, 'dcount': 36550, 'month': None}, {'year': None, 'start_operator_alias': 4, 'dcount': 25714, 'month': None}, {'year': None, 'start_operator_alias': 8, 'dcount': 200, 'month': None}]>

如您所见,月份和年份返回为无。可能是什么原因或我做错了什么。

model:
class FeedbackData(models.Model):
  deviceId = models.CharField(blank=True, null=True, max_length=64, db_tablespace="indexes")
  start_cellId = models.CharField(null=True, blank=True, max_length=32)
  end_cellId = models.CharField(null=True, blank=True, max_length=32)
  start_mcc = models.CharField(null=True, blank=True, max_length=32)
  end_mcc = models.CharField(null=True, blank=True, max_length=32)
  start_mnc = models.CharField(null=True, blank=True, max_length=32)
  end_mnc = models.CharField(null=True, blank=True, max_length=32)
  start_lac = models.CharField(null=True, blank=True, max_length=32)
  end_lac = models.CharField(null=True, blank=True, max_length=32)
  start_operator_name = models.CharField(db_index=True, null=True, max_length=32, blank=True)
  start_operator_alias = models.IntegerField(db_index=True, null=True, default=-1)
  end_operator_name = models.CharField(db_index=True, null=True, max_length=32, blank=True)
  end_operator_alias = models.IntegerField(db_index=True, null=True, default=-1)
  start_signal_strength = models.CharField(null=True, blank=True, max_length=32)
  end_signal_strength = models.CharField(null=True, blank=True, max_length=32)
  average_signal_strength = models.CharField(null=True, blank=True, max_length=32)
  phone_type = models.CharField(db_index=True, null=True, blank=True, max_length=8, default='unknown')
  call_duration = models.IntegerField(db_index=True, null=True, blank=True, default=0)
  network_type = models.CharField(db_index=True, null=True, blank=True, max_length=16, default='unknown')
  start_cell_signal_strength = models.CharField(null=True, blank=True, max_length=32)
  end_cell_signal_strength = models.CharField(null=True, blank=True, max_length=32)
  device_model = models.CharField(null=True, blank=True, max_length=64)
  device_manufacturer = models.CharField(db_index=True, null=True, blank=True, max_length=64)
  os_version = models.CharField(db_index=True, null=True, blank=True, max_length=32)
  start_time_of_call = models.DateTimeField(blank=True, null=True)
  end_time_of_call = models.DateTimeField(blank=True, null=True)
  start_lon = models.FloatField(db_index=True, null=True, blank=True)
  start_lat = models.FloatField(db_index=True, null=True, blank=True)
  end_lon = models.FloatField(db_index=True, null=True, blank=True)
  end_lat = models.FloatField(db_index=True, null=True, blank=True)
  start_lon_rad = models.FloatField(db_index=True, null=True, blank=True) 
  start_lat_rad = models.FloatField(db_index=True, null=True, blank=True)
  end_lon_rad = models.FloatField(db_index=True, null=True, blank=True)
  end_lat_rad = models.FloatField(db_index=True, null=True, blank=True)
  start_cdma_lon = models.FloatField(db_index=True, null=True, blank=True)
  start_cdma_lat = models.FloatField(db_index=True, null=True, blank=True)
  end_cdma_lon = models.FloatField(db_index=True, null=True, blank=True)
  end_cdma_lat = models.FloatField(db_index=True, null=True, blank=True)
  rating_time = models.DateTimeField(blank=True, null=True)
  speed = models.FloatField(null=True, blank=True)
  altitude = models.FloatField(null=True, blank=True)
  is_dual = models.BooleanField(db_index=True, default=False)
  is_roaming = models.BooleanField(db_index=True, default=False)
  is_network_roaming = models.BooleanField(default=False)
  call_drop = models.IntegerField(db_index=True, null=True)
  rating = models.FloatField(db_index=True, null=True, blank=True)
  state_name = models.CharField(db_index=True, null=True, blank=True, max_length=255)
  additional_info = models.CharField(db_index=True, null=True, blank=True, max_length=216)
  comment = models.CharField(null=True, blank=True, max_length=512)
  in_out = models.IntegerField(db_index=True, null=True)
  created = models.DateTimeField(db_index=True, auto_now_add=True)

1 个答案:

答案 0 :(得分:0)

如果您没有将任何时区信息加载到mysql中,则会发生这种情况

convert_tz returns null