繁体   English   中英

如何在 pyhton django 中的每个循环上添加日期时间格式分钟

[英]How to add datetime format minute on each loop in pyhton django

这是我的代码。 我想在循环中添加 25 分钟然后保存在数据库中,

我尝试了一种解决方案,但它只加了 1 次加 25 分钟。 我希望第一次系统在日期时间的第二个循环中输入实际日期时间加上 25 分钟。

service_obj = Service.objects.get(id=1)
startingDate = datetime.strptime(startingDate, '%d-%m-%Y %I:%M %p').strftime("%Y-%m-%d %H:%M:00+00")

service_fee = StaffServiceFee.objects.filter(service_id=service_obj.id).values_list('service_charges', 'staff_user').order_by('id')

for service_fees in service_fee:
    obj = UserAppointments.objects.create(customer_id=1,
           staff_user_id=service_fees[1],
          service=service_obj,
           status="1")
 obj.date_time = startingDate
 obj.save()

检查解决方案。

for service_fees in service_fee:
                print(service_fees[1])
                obj = UserAppointments.objects.create(customer=customer_obj,
                                                      staff_user_id=service_fees[1],
                                                      service=service_obj,
                                                      status="1"
                                                      )



                # obj.date_time = startingDate
                obj.date_time = startingDate
                obj.save()

                startingDate = ( datetime.strptime(startingDate, "%Y-%m-%d %H:%M:00+00") + timedelta(minutes=25)).strftime("%Y-%m-%d %H:%M:00+00")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM