@@ -462,7 +462,7 @@ class Occurrence(models.Model):
462462 original_end = models .DateTimeField (("original end" ))
463463 created_on = models .DateTimeField (("created on" ), auto_now_add = True )
464464 updated_on = models .DateTimeField (("updated on" ), auto_now = True )
465- interval = models .IntegerField (("interval" ), blank = True , validators = [ MinValueValidator ( 5 ), MaxValueValidator ( 60 )] )
465+ interval = models .IntegerField (("interval" ), blank = True , null = True )
466466
467467 class Meta :
468468 verbose_name = ("occurrence" )
@@ -482,21 +482,22 @@ def __init__(self, *args, **kwargs):
482482 def save (self , * args , ** kwargs ):
483483 super ().save (* args , ** kwargs )
484484
485- if self .pk : # If save is called on object update, not creation
486- self .bookings .all ().delete ()
487-
488- delta = self .end - self .start
489- delta_minutes = delta .total_seconds () / 60
490- booking_count = int (delta_minutes // self .interval )
491- for i in range (booking_count ):
492- booking_start = self .start + timedelta (minutes = i * self .interval )
493- booking_end = booking_start + timedelta (minutes = self .interval )
494- Booking .objects .create (
495- occurrence = self ,
496- user = None ,
497- start = booking_start ,
498- end = booking_end ,
499- )
485+ if self .interval is not None :
486+ if self .pk : # If save is called on object update, not creation
487+ self .bookings .all ().delete ()
488+
489+ delta = self .end - self .start
490+ delta_minutes = delta .total_seconds () / 60
491+ booking_count = int (delta_minutes // self .interval )
492+ for i in range (booking_count ):
493+ booking_start = self .start + timedelta (minutes = i * self .interval )
494+ booking_end = booking_start + timedelta (minutes = self .interval )
495+ Booking .objects .create (
496+ occurrence = self ,
497+ user = None ,
498+ start = booking_start ,
499+ end = booking_end ,
500+ )
500501
501502 def moved (self ):
502503 return self .original_start != self .start or self .original_end != self .end
0 commit comments