django使用ORM(PostgreSQL)覆盖的日期如何分开持续时间。
使用Django(带有PostgreSQL),我有一个模型,该模型代表具有一定的起始时刻(start_dateTime)和持续时间的活动。
因此,一项活动可能覆盖了一天以上,我想知道连续日期(天)上它涵盖了多少时间。因此,一个例子是,所有使用UTC时区都将在2022-12-24T12:00开始48小时的约会,这将在20222-12-26T12:00上结束,每天给予持续时间:
- 2022-12 -24-12小时
- 2022-12-25-24小时
- 2022-12-26-12小时
,我想获取此信息以进行一年的活动,以提供一个人的日历。
这是可能的吗?理想情况下,我还可以指定需要确定此数据的时区。
Using Django (with PostgreSQL) I have a model that represents activities with a certain starting moment (start_datetime) and a duration.
So it is possible that an activity covers more than one day, and I would like to know per activity how much time it covers on consecutive dates (days). So an example would be, all using UTC timezone, to have a 48 hour appointment start on 2022-12-24T12:00, which would have the activity end on 2022-12-26T12:00, giving duration per day:
- 2022-12-24 - 12 hours
- 2022-12-25 - 24 hours
- 2022-12-26 - 12 hours
And I would like to get this information for up to a year's worth of activities, for a single person's calendar.
Is this possible, and if so does anyone have an example of how to achieve this? Ideally I would also be able to specify the timezone that this data needs to be determined in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
models.durationfield
(you can use
models.DurationField
(https://www.geeksforgeeks.org/durationfield-django-models/) and specify any duration, also in the model you need to create a field from which moment to count and either indicate what the timezone is there or save it separately in the field for each record