Fonction de création de quart de travail Django Ajout de la fonction d'enregistrement de travail de base pendant des jours

① Table de décalage: seul l'administrateur peut modifier l'heure. (2) Tableau des équipes: je veux que vous copiez la création de l'équipe par jour ③ Quart de travail souhaité: le 5 de chaque mois, nous demandons une demande de quart et la créons et la distribuons avant le 10, donc les restrictions d'entrée pour l'entrée par 5 ④ Tableau d'affichage: informez chaque établissement ⑤ Tâche Il est préférable que vous puissiez reprendre ce que vous avez à faire

Puisque ① est terminé, c'est ② que nous avons commencé.

J'ai créé une nouvelle table BaseShift avec des informations utilisateur et y ai enregistré le quart de travail de base.

schedule/models.py


class BaseShift(models.Model):
    id = models.AutoField(verbose_name='ID d'équipe souhaité',primary_key=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Nom de l'employé')
    getsu_shift_name_1 = models.ForeignKey(Shift, verbose_name='Mois_1 nom d'équipe', related_name='base_shift_getsu_shift_name_1',on_delete=models.SET_NULL,null= True)
    getsu_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='Mois_1 établissement', related_name='base_shift_getsu_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shift_name_2 = models.ForeignKey(Shift, verbose_name='Mois_2 nom d'équipe', related_name='base_shift_getsu_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='Mois_2 installations', related_name='base_shift_getsu_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shift_name_3 = models.ForeignKey(Shift, verbose_name='Mois_3 nom d'équipe', related_name='base_shift_getsu_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='Mois_3 installations', related_name='base_shift_getsu_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shift_name_4 = models.ForeignKey(Shift, verbose_name='Mois_4 nom d'équipe', related_name='base_shift_getsu_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    getsu_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='Mois_4 établissements', related_name='base_shift_getsu_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    ka_shift_name_1 = models.ForeignKey(Shift, verbose_name='Feu_1 nom d'équipe', related_name='base_shift_ka_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='Feu_1 établissement', related_name='base_shift_ka_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shift_name_2 = models.ForeignKey(Shift, verbose_name='Feu_2 nom d'équipe', related_name='base_shift_ka_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='Feu_2 installations', related_name='base_shift_ka_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shift_name_3 = models.ForeignKey(Shift, verbose_name='Feu_3 nom d'équipe', related_name='base_shift_ka_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='Feu_3 installations', related_name='base_shift_ka_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shift_name_4 = models.ForeignKey(Shift, verbose_name='Feu_4 nom d'équipe', related_name='base_shift_ka_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    ka_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='Feu_4 établissements', related_name='base_shift_ka_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    sui_shift_name_1 = models.ForeignKey(Shift, verbose_name='eau_1 nom d'équipe', related_name='base_shift_sui_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='eau_1 établissement', related_name='base_shift_sui_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shift_name_2 = models.ForeignKey(Shift, verbose_name='eau_2 nom d'équipe', related_name='base_shift_sui_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='eau_2 installations', related_name='base_shift_sui_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shift_name_3 = models.ForeignKey(Shift, verbose_name='eau_3 nom d'équipe', related_name='base_shift_sui_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='eau_3 installations', related_name='base_shift_sui_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shift_name_4 = models.ForeignKey(Shift, verbose_name='eau_4 nom d'équipe', related_name='base_shift_sui_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    sui_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='eau_4 établissements', related_name='base_shift_sui_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    moku_shift_name_1 = models.ForeignKey(Shift, verbose_name='bois_1 nom d'équipe', related_name='base_shift_moku_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='bois_1 établissement', related_name='base_shift_moku_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shift_name_2 = models.ForeignKey(Shift, verbose_name='bois_2 nom d'équipe', related_name='base_shift_moku_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='bois_2 installations', related_name='base_shift_moku_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shift_name_3 = models.ForeignKey(Shift, verbose_name='bois_3 nom d'équipe', related_name='base_shift_moku_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='bois_3 installations', related_name='base_shift_moku_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shift_name_4 = models.ForeignKey(Shift, verbose_name='bois_4 nom d'équipe', related_name='base_shift_moku_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    moku_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='bois_4 établissements', related_name='base_shift_moku_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    kin_shift_name_1 = models.ForeignKey(Shift, verbose_name='Argent_1 nom d'équipe', related_name='base_shift_kin_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='Argent_1 établissement', related_name='base_shift_kin_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shift_name_2 = models.ForeignKey(Shift, verbose_name='Argent_2 nom d'équipe', related_name='base_shift_kin_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='Argent_2 installations', related_name='base_shift_kin_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shift_name_3 = models.ForeignKey(Shift, verbose_name='Argent_3 nom d'équipe', related_name='base_shift_kin_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='Argent_3 installations', related_name='base_shift_kin_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shift_name_4 = models.ForeignKey(Shift, verbose_name='Argent_4 nom d'équipe', related_name='base_shift_kin_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    kin_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='Argent_4 établissements', related_name='base_shift_kin_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    do_shift_name_1 = models.ForeignKey(Shift, verbose_name='sol_1 nom d'équipe', related_name='base_shift_do_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    do_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='sol_1 établissement', related_name='base_shift_do_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    do_shift_name_2 = models.ForeignKey(Shift, verbose_name='sol_2 nom d'équipe', related_name='base_shift_do_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    do_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='sol_2 installations', related_name='base_shift_do_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    do_shift_name_3 = models.ForeignKey(Shift, verbose_name='sol_3 nom d'équipe', related_name='base_shift_do_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    do_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='sol_3 installations', related_name='base_shift_do_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    do_shift_name_4 = models.ForeignKey(Shift, verbose_name='sol_4 nom d'équipe', related_name='base_shift_do_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    do_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='sol_4 établissements', related_name='base_shift_do_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

    nichi_shift_name_1 = models.ForeignKey(Shift, verbose_name='journée_1 nom d'équipe', related_name='base_shift_nichi_shift_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='journée_1 établissement', related_name='base_shift_nichi_shisetsu_name_1',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shift_name_2 = models.ForeignKey(Shift, verbose_name='journée_2 nom d'équipe', related_name='base_shift_nichi_shift_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='journée_2 installations', related_name='base_shift_nichi_shisetsu_name_2',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shift_name_3 = models.ForeignKey(Shift, verbose_name='journée_3 nom d'équipe', related_name='base_shift_nichi_shift_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='journée_3 installations', related_name='base_shift_nichi_shisetsu_name_3',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shift_name_4 = models.ForeignKey(Shift, verbose_name='journée_4 nom d'équipe', related_name='base_shift_nichi_shift_name_4',on_delete=models.SET_NULL,blank=True, null=True)
    nichi_shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='journée_4 établissements', related_name='base_shift_nichi_shisetsu_name_4',on_delete=models.SET_NULL,blank=True, null=True)

Je ne sais pas s'il vaut mieux faire comme ça, mais si vous ne suivez pas la méthode précédente, cela peut affecter d'autres choses, donc ça fait longtemps, mais je l'ai fait avec cette méthode.

schedule/views.py


def schedulecreatefunc(request,year_num,month_num):
    year, month = int(year_num), int(month_num)
    #Supprimer tous les horaires de l'année et du mois cibles
    Schedule.objects.filter(year = year, month = month).delete()
    #Obtenez le nombre de jours dans la plage de travail
    enddate = datetime.date(year,month,20)
    startdate = enddate + relativedelta(months=-1)
    #Extraire l'espoir de la période cible du décalage souhaité
    kiboushift_list = KibouShift.objects.filter(date__range=[startdate, enddate])
    kiboushift_list = list(kiboushift_list)
    shift_list = Shift.objects.all()
    
    #Refléter le décalage souhaité
    for kibou in kiboushift_list:
        sum_work_time = 0
        for shift in shift_list:
                if str(kibou.shift_name_1) == str(shift.name):
                    sum_work_time = shift.wrok_time + sum_work_time
                if str(kibou.shift_name_2) == str(shift.name):
                    sum_work_time = shift.wrok_time + sum_work_time
                if str(kibou.shift_name_3) == str(shift.name):
                    sum_work_time = shift.wrok_time + sum_work_time
                if str(kibou.shift_name_4) == str(shift.name):
                    sum_work_time = shift.wrok_time + sum_work_time
        new_object = Schedule(
            user = kibou.user,
            date = kibou.date, 
            year = year,
            month = month,
            shift_name_1 = kibou.shift_name_1, 
            shisetsu_name_1 = kibou.shisetsu_name_1,
            shift_name_2 = kibou.shift_name_2, 
            shisetsu_name_2 = kibou.shisetsu_name_2,
            shift_name_3 = kibou.shift_name_3, 
            shisetsu_name_3 = kibou.shisetsu_name_3,
            shift_name_4 = kibou.shift_name_4, 
            shisetsu_name_4 = kibou.shisetsu_name_4,
            day_total_worktime = sum_work_time,
            )
        new_object.save()
    
    #Créer une équipe autre que celle souhaitée
    user_list = User.objects.all()
    #Obtenez le nombre de jours dans la plage de travail
    enddate = datetime.date(year,month,20)
    startdate = enddate + relativedelta(months=-1)
    kaisu = enddate - startdate
    kaisu = int(kaisu.days) 
    #le mois dernier
    if month != 1 :
        zengetsu = month - 1
    else:
        zengetsu = 12
        year = year - 1
    #Processus pour chaque utilisateur
    for user in user_list:
        #base_Créé à partir des informations où le décalage est enregistré
        base_shift = BaseShift.objects.filter(user = user.id)
        kongetsu_list = Schedule.objects.filter(year = year, month = month, user = user.id).order_by('date')
        zengetsu_list = Schedule.objects.filter(year = year, month = zengetsu, user = user.id).order_by('date')
        sakusei_date = startdate
        shift_list = Shift.objects.all()
        for new_shift in range(kaisu):
            sakusei_date = sakusei_date + timedelta(days=1)
            if kongetsu_list.filter(user = user.id, date = sakusei_date).exists():
                print("ok")                       
            else:
                weekdays = ["Mois","Feu","eau","bois","Argent","sol","journée"]
                youbi = weekdays[sakusei_date.weekday()] 

                #Obtenez de l'équipe de base et obtenez
                if base_shift.filter(user = user.id ).exists():
                    for base in base_shift:
                        sum_work_time = 0
                        shift1 = None
                        shisetsu1 = None
                        shift2 = None
                        shisetsu2 = None
                        shift3 = None
                        shisetsu3 = None
                        shift4 = None
                        shisetsu4 = None

                        if youbi == "Mois":
                            for shift in shift_list:
                                if str(base.getsu_shift_name_1) == str(shift.name):
                                    shift1 = base.getsu_shift_name_1
                                    shisetsu1 = base.getsu_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.getsu_shift_name_2) == str(shift.name):
                                    shift2 = base.getsu_shift_name_2
                                    shisetsu2 = base.getsu_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.getsu_shift_name_3) == str(shift.name):
                                    shift3 = base.getsu_shift_name_3
                                    shisetsu3 = base.getsu_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.getsu_shift_name_4) == str(shift.name):
                                    shift4 = base.getsu_shift_name_4
                                    shisetsu4 = base.getsu_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time
                        
                        elif youbi == "Feu":
                            for shift in shift_list:
                                if str(base.ka_shift_name_1) == str(shift.name):
                                    shift1 = base.ka_shift_name_1
                                    shisetsu1 = base.ka_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.ka_shift_name_2) == str(shift.name):
                                    shift2 = base.ka_shift_name_2
                                    shisetsu2 = base.ka_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.ka_shift_name_3) == str(shift.name):
                                    shift3 = base.ka_shift_name_3
                                    shisetsu3 = base.ka_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.ka_shift_name_4) == str(shift.name):
                                    shift4 = base.ka_shift_name_4
                                    shisetsu4 = base.ka_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time
                    
                        elif youbi == "eau":
                            for shift in shift_list:
                                if str(base.sui_shift_name_1) == str(shift.name):
                                    shift1 = base.sui_shift_name_1
                                    shisetsu1 = base.sui_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.sui_shift_name_2) == str(shift.name):
                                    shift2 = base.sui_shift_name_2
                                    shisetsu2 = base.sui_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.sui_shift_name_3) == str(shift.name):
                                    shift3 = base.sui_shift_name_3
                                    shisetsu3 = base.sui_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.sui_shift_name_4) == str(shift.name):
                                    shift4 = base.sui_shift_name_4
                                    shisetsu4 = base.sui_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time

                        elif youbi == "bois":
                            for shift in shift_list:
                                if str(base.moku_shift_name_1) == str(shift.name):
                                    shift1 = base.moku_shift_name_1
                                    shisetsu1 = base.moku_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.moku_shift_name_2) == str(shift.name):
                                    shift2 = base.moku_shift_name_2
                                    shisetsu2 = base.moku_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.moku_shift_name_3) == str(shift.name):
                                    shift3 = base.moku_shift_name_3
                                    shisetsu3 = base.moku_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.moku_shift_name_4) == str(shift.name):
                                    shift4 = base.moku_shift_name_4
                                    shisetsu4 = base.moku_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time

                        elif youbi == "Argent":
                            for shift in shift_list:
                                if str(base.kin_shift_name_1) == str(shift.name):
                                    shift1 = base.kin_shift_name_1
                                    shisetsu1 = base.kin_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.kin_shift_name_2) == str(shift.name):
                                    shift2 = base.kin_shift_name_2
                                    shisetsu2 = base.kin_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.kin_shift_name_3) == str(shift.name):
                                    shift3 = base.kin_shift_name_3
                                    shisetsu3 = base.kin_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.kin_shift_name_4) == str(shift.name):
                                    shift4 = base.kin_shift_name_4
                                    shisetsu4 = base.kin_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time

                        elif youbi == "sol":
                            for shift in shift_list:
                                if str(base.do_shift_name_1) == str(shift.name):
                                    shift1 = base.do_shift_name_1
                                    shisetsu1 = base.do_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.do_shift_name_2) == str(shift.name):
                                    shift2 = base.do_shift_name_2
                                    shisetsu2 = base.do_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.do_shift_name_3) == str(shift.name):
                                    shift3 = base.do_shift_name_3
                                    shisetsu3 = base.do_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.do_shift_name_4) == str(shift.name):
                                    shift4 = base.do_shift_name_4
                                    shisetsu4 = base.do_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time

                        if youbi == "journée":
                            for shift in shift_list:
                                if str(base.nichi_shift_name_1) == str(shift.name):
                                    shift1 = base.nichi_shift_name_1
                                    shisetsu1 = base.nichi_shisetsu_name_1
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.nichi_shift_name_2) == str(shift.name):
                                    shift2 = base.nichi_shift_name_2
                                    shisetsu2 = base.nichi_shisetsu_name_2
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.nichi_shift_name_3) == str(shift.name):
                                    shift3 = base.nichi_shift_name_3
                                    shisetsu3 = base.nichi_shisetsu_name_3
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(base.nichi_shift_name_4) == str(shift.name):
                                    shift4 = base.nichi_shift_name_4
                                    shisetsu4 = base.nichi_shisetsu_name_4
                                    sum_work_time = shift.wrok_time + sum_work_time

                        new_object=Schedule(
                        user = base.user,
                        date = sakusei_date,
                        year = year,
                        month = month,
                        shift_name_1 = shift1, 
                        shisetsu_name_1 = shisetsu1,
                        shift_name_2 = shift2, 
                        shisetsu_name_2 = shisetsu2,
                        shift_name_3 = shift3, 
                        shisetsu_name_3 = shisetsu3,
                        shift_name_4 = shift4, 
                        shisetsu_name_4 = shisetsu4,
                        day_total_worktime = sum_work_time,
                        )
                        new_object.save()
                else:
                    hukushadate = sakusei_date + relativedelta(months=-1)
                    hukusha_list = zengetsu_list.filter(date = hukushadate, user = user.id)
                    if zengetsu_list.filter(date = hukushadate, user = user.id).exists():
                        for hukusha in hukusha_list:
                        #Calculer le nombre total d'heures de travail quotidiennes des quarts
                            sum_work_time = 0
                            for shift in shift_list:
                                if str(hukusha.shift_name_1) == str(shift.name):
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(hukusha.shift_name_2) == str(shift.name):
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(hukusha.shift_name_3) == str(shift.name):
                                    sum_work_time = shift.wrok_time + sum_work_time
                                if str(hukusha.shift_name_4) == str(shift.name):
                                    sum_work_time = shift.wrok_time + sum_work_time

                            new_object=Schedule(
                                user = hukusha.user,
                                date = sakusei_date,
                                year = year,
                                month = month,
                                shift_name_1 = hukusha.shift_name_1, 
                                shisetsu_name_1 = hukusha.shisetsu_name_1,
                                shift_name_2 = hukusha.shift_name_2, 
                                shisetsu_name_2 = hukusha.shisetsu_name_2,
                                shift_name_3 = hukusha.shift_name_3, 
                                shisetsu_name_3 = hukusha.shisetsu_name_3,
                                shift_name_4 = hukusha.shift_name_4, 
                                shisetsu_name_4 = hukusha.shisetsu_name_4,
                                day_total_worktime = sum_work_time,
                                )
                            new_object.save()
                    else:
                        useradd = User.objects.get(id=user.id)
                        shiftadd = Shift.objects.get(id=2)
                        new_object=Schedule(
                        user = useradd,
                        date = sakusei_date,
                        year = year,
                        month = month,
                        shift_name_1 = shiftadd, 
                        shisetsu_name_1 = None,
                        shift_name_2 = None, 
                        shisetsu_name_2 = None,
                        shift_name_3 = None, 
                        shisetsu_name_3 = None,
                        shift_name_4 = None, 
                        shisetsu_name_4 = None,
                        day_total_worktime = 0,
                        )
                        new_object.save()
    return HttpResponseRedirect('/schedule/monthschedule/%s/%s/' % (year,month,))

Désormais, si BaseShift est enregistré, il sera traité en premier avant de copier la date du mois précédent.

Organiser

    1. Gérer le décalage souhaité
  1. Traiter s'il y a un décalage de base
    1. Copier le même jour du mois précédent

Ce sera l'état avant l'édition!

Cela a pris quelques heures, mais je suis content d'avoir pu confirmer l'opération en toute sécurité!

Recommended Posts

Fonction de création de quart de travail Django Ajout de la fonction d'enregistrement de travail de base pendant des jours
Ajout d'une fonction pour enregistrer les décalages souhaités dans la table des décalages Django
Fonction de création de données de décalage de table Django terminée
Représentation numérique des jours dans différentes langues
[Django] Ajout d'une nouvelle fonction de création de questions à l'application de sondages
Fonction de création de décalage Django
Résumé des points d'achoppement à Django pour la première fois
La fonction d'affichage d'image d'iTerm est pratique lors du traitement d'images.