diff --git a/rowers/models.py b/rowers/models.py index 00fd6da7..4b4e5a73 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -1227,6 +1227,21 @@ def microcyclecheckdates(plan): thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + cycles = TrainingMicroCycle.objects.filter( + plan=plan + ).order_by("startdate") + + thedate = plan.startdate + while cycles: + if cycles[0].startdate < thedate: + cycles[0].startdate = thedate + cycles[0].save() + try: + thedate = cycles[1].startdate-datetime.timedelta(days=1) + except IndexError: + pass + cycles = cycles[1:] + def mesocyclecheckdates(plan): cycles = TrainingMesoCycle.objects.filter( plan=plan @@ -1276,6 +1291,20 @@ def macrocyclecheckdates(plan): thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + cycles = TrainingMacroCycle.objects.filter( + plan=plan + ).order_by("startdate") + + thedate = plan.startdate + while cycles: + if cycles[0].startdate < thedate: + cycles[0].startdate = thedate + cycles[0].save() + try: + thedate = cycles[1].startdate-datetime.timedelta(days=1) + except IndexError: + pass + cycles = cycles[1:] class TrainingMacroCycle(models.Model): plan = models.ForeignKey(TrainingPlan)