0002_auto_20170912_1346.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:timed-backend 作者: adfinis-sygroup 项目源码 文件源码
def migrate_activity_block_time(apps, schema_editor):
    """
    Convert hours to Django time zone.

    Activity block time is in UTC but once it is converted
    to time we actually want time as it would be represented
    in settings.TIME_ZONE
    """
    current_tz = timezone(settings.TIME_ZONE)
    ActivityBlock = apps.get_model('tracking', 'ActivityBlock')
    for block in ActivityBlock.objects.all():
        if block.to_datetime is not None:
            block.to_datetime = block.to_datetime.astimezone(current_tz).replace(tzinfo=utc)
        block.from_datetime = block.from_datetime.astimezone(current_tz).replace(tzinfo=utc)
        block.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号