Django 的“User”模型的每日复合聚合; “date_joined”字段(用于使用 Highcharts 绘图)
我想使用 User
模型并使用 date_joined
字段按天将其分解。 Django 的 聚合 似乎很合适,但我不确定如何将其与 DateField 对象一起使用。我相信我也希望价值观复合。
我的目标是获得从第一次注册到最近(并继续)每天的整数。我认为我希望采用复合形式,例如,如果第一天我有 100 个注册,第二天是 80 个,我希望第二天的总数为 180。这样我就可以看到用户群随着时间的推移而增长/下降,而不仅仅是注册人数激增,然后在没有注册的日子里趋于平稳。
非常确定使用 Highcharts 来绘制图表。这是我希望实现的图表的一个实时示例,仅使用苹果股票数据,但这或多或少是我想要的,仅包含每日用户注册量。 http://www.highcharts.com/stock/demo/basic-line
我可以使用以下示例构建单个实例的 QuerySet。但这并不是一个非常现实的方法。我想动态计算这些数字,而不是手动分配它们。
<代码> y2007m09d01=(user_list.filter(date_joined__year="2007").filter(date_joined__month="9").filter(date_joined__day="1").count())
y2007m09d02=(user_list.filter(date_joined__year="2007").filter(date_joined__month="9").filter(date_joined__day="1").count() + y2007m09d01)
I would like to take my User
model and break it down by day, using the date_joined
field. Django's aggregation seems to be a good fit, but im not sure how to use this with a DateField object. I believe I also want the values to compound.
My goal is to get a whole number for each day since the very first signup to the most present (and continuing). I think I want this in compound form, so for example, if the first day i have 100 signups and the day after is 80, I want the second days total to be 180. This way I can see the userbase grow/drop over time and not just see signup spikes and then flatline on days that there are no signups.
Pretty set on using Highcharts for the graphing. Here is a live example of the graph I wish to implement, only using Apple stock data but it's more or less what I want, only with daily amounts of user signup. http://www.highcharts.com/stock/demo/basic-line
I can build a QuerySet of a single instance with the following example. This isn't a very realistic approach going forward though. I'd like to dynamically calculate these figures, not manually assign them.
y2007m09d01=(user_list.filter(date_joined__year="2007").filter(date_joined__month="9").filter(date_joined__day="1").count())
y2007m09d02=(user_list.filter(date_joined__year="2007").filter(date_joined__month="9").filter(date_joined__day="1").count() + y2007m09d01)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有一些“all django”解决方案,但如果没有,你可以使用 itertools.groupby 用户列表。我在想这样的事情:
There might be some "all django" solution to this, but if not you can just use itertools.groupby over the list of users. I'm thinking something like this: