fix(pages.py): fix event's other occurrences not being deleted when changing event from recurrent to single
Closes #1
This commit is contained in:
@@ -330,12 +330,15 @@ class EventPage(Page):
|
|||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
if not self.recurrence_enabled:
|
if not self.recurrence_enabled:
|
||||||
# if recurrence is not enabled, ensure there's at least one occurrence for the specified start/end
|
# if recurrence is not enabled, ensure there's at least one occurrence for the specified start/end
|
||||||
|
# and delete any other occurrences that don't match the current start/end
|
||||||
if self.occurrences.exists():
|
if self.occurrences.exists():
|
||||||
occurrence = self.occurrences.first()
|
occurrence = self.occurrences.first()
|
||||||
if occurrence.start != self.start or occurrence.end != self.end:
|
if occurrence.start != self.start or occurrence.end != self.end:
|
||||||
occurrence.start = self.start
|
occurrence.start = self.start
|
||||||
occurrence.end = self.end
|
occurrence.end = self.end
|
||||||
occurrence.save(update_fields=["start", "end"])
|
occurrence.save(update_fields=["start", "end"])
|
||||||
|
|
||||||
|
self.occurrences.exclude(id=occurrence.id).delete()
|
||||||
else:
|
else:
|
||||||
EventOccurrence.objects.create(
|
EventOccurrence.objects.create(
|
||||||
event=self, start=self.start, end=self.end
|
event=self, start=self.start, end=self.end
|
||||||
|
|||||||
Reference in New Issue
Block a user