我有shift一个日期时间间隔(一对datetimes)。我的周有一个带标签的分区(每周都是一样的:分为几个部分,每个部分都有一个标签)。我想shift根据一周的划分分成标记部分(即分成几个子区间)。
例子。假设shift区间为2019-10-21 18:30- 2019-10-22 08:00,一周的划分如下:周一至周五 07:00 - 19:00 有 label A,本周其余时间有 label B。在这种情况下,分割shift应该是以下标记的子区间列表:
2019-10-21 18:30-2019-10-21 19:00带标签A,2019-10-21 19:00-2019-10-22 07:00带标签B,以及2019-10-22 07:00-2019-10-22 08:00带标签A。一般情况下我该如何做到这一点?
输入:一个datetime间隔(对)和一周的标记分区(如何最好地表示这一点?)
输出:datetime标记间隔(对)的列表。
请注意,shift可以在一周内开始并在另一周内结束(例如周日晚上到周一早上);每周都有相同的标记分区。
I am using django-import-export 1.0.1 with admin integration in Django 2.1.1. I have two models
\n\nfrom django.db import models\n\nclass Sector(models.Model):\n code = models.CharField(max_length=30, primary_key=True)\n\nclass Location(models.Model):\n code = models.CharField(max_length=30, primary_key=True)\n sector = ForeignKey(Sector, on_delete=models.CASCADE, related_name=\'locations\')\nRun Code Online (Sandbox Code Playgroud)\n\n并且可以使用模型资源很好地导入/导出它们
\n\nfrom import_export import resources\nfrom import_export.fields import Field\nfrom import_export.widgets import ForeignKeyWidget\n\nclass SectorResource(resources.ModelResource):\n code = Field(attribute=\'code\', column_name=\'Sector\')\n class Meta:\n model = Sector\n import_id_fields = (\'code\',)\n\nclass LocationResource(resources.ModelResource):\n code = Field(attribute=\'code\', column_name=\'Location\')\n sector = Field(attribute=\'sector\', column_name=\'Sector\',\n widget=ForeignKeyWidget(Sector, \'code\'))\n class Meta:\n model = Location\n import_id_fields = (\'code\',)\n …Run Code Online (Sandbox Code Playgroud) python django django-forms django-admin django-import-export