如何按月份而不是按天筛选现有查询集

2024-09-30 12:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个查询集,显示每月每天的关注者数量

enter image description here

视图:

context["brandtwitterFollowerCounts"] = (
    TwitterFollowerCount.objects.filter(
        twitter_account=self.object.twitter_account, followers__gt=0
    )
    .distinct("created__date")
    .order_by("created__date")
)
context["brandTwitterFollowCreated"] = [
    i.created.strftime("%d %m") for i in context["brandtwitterFollowerCounts"]
]
context["brandTwitterFollowers"] = [
    i.followers for i in context["brandtwitterFollowerCounts"]

数据集:

var newDataObjectTwo = {
  labels: {{ brandTwitterFollowCreated|safe }},
  datasets: [{
      label: 'Daily',
      backgroundColor: 'rgb(255, 255, 255)',
      fill: false,
      borderColor: 'rgb(29, 161, 242)',
      data: {{ brandTwitterFollowers|safe }}
  }],
}

我想过滤这个月,而不是现在。因此,由于目前有3个月(08、09、10),图表应该只显示3个数据点。抱歉,如果这不合理,我不知道什么是最好的解释方式


Tags: 数据infor数量datecontexttwitteraccount

热门问题