Last active
February 18, 2019 23:00
-
-
Save CoutinhoElias/5431b6d647755f7d062adc9b8c48c4c7 to your computer and use it in GitHub Desktop.
MelhorarFuncao
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render, redirect, get_object_or_404 | |
import calendar | |
import datetime | |
def add_work_schedule_item(**data): | |
first_weekday, num_days_in_month = calendar.monthrange(2019, 2) | |
work_schedule = get_object_or_404(WorkSchedule, pk=3) | |
for day_number in range(1, num_days_in_month + 1): | |
a = "02/2019" | |
m, y = a.split('/') | |
strdate = datetime.datetime(int(y), int(m), day_number) | |
WorkScheduleItem.objects.get_or_create(day=strdate, workschedule=work_schedule) |
o range do python não inclui o último número da sequência, por isso, acho que cê precisa colocar um num_days_in_month + 1
como segundo parâmetro do range
Sugestão:
Troque isso:
a = "02/2019" m, y = a.split('/') strdate = datetime.datetime(int(y), int(m), day_number)
Por isso:
strdate = datetime.datetime(2019, 2, day_number)
Vinicius, devido precisar importar de um forms.py do django eu preciso fazer split pois irei preencher apenas mês e ano.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sugestão:
Troque isso:
Por isso: