Skip to content
Snippets Groups Projects
Verified Commit 6b9a973b authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

fix: don’t use bulk_create and don’t ignore conflicts

parent 383f2db8
No related branches found
No related tags found
No related merge requests found
Pipeline #7797 passed
......@@ -3,6 +3,7 @@ from datetime import datetime
from dateutil.rrule import rrule
from django.core.management import BaseCommand
from django.db import IntegrityError
from django.utils.timezone import make_aware
from program.models import RRule, Schedule, TimeSlot
......@@ -34,6 +35,8 @@ class Command(BaseCommand):
for schedule in (
Schedule.objects.exclude(rrule=once).filter(last_date=None).order_by("show__name")
):
added = 0
skipped = 0
last_timeslot = schedule.timeslots.last()
# add timeslots to the schedules with no timeslot this year
......@@ -65,8 +68,16 @@ class Command(BaseCommand):
)
)
else:
TimeSlot.objects.bulk_create(timeslots, ignore_conflicts=True)
for timeslot in timeslots:
try:
timeslot.save()
except IntegrityError:
skipped += 1
else:
added += 1
self.stdout.write(
self.style.SUCCESS(f"added {str(len(timeslots))} timeslots to {schedule}")
self.style.SUCCESS(
f"added {str(added)} timeslots to {schedule}, skipped {str(skipped)}"
)
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment