@@ -462,7 +462,7 @@ class Occurrence(models.Model):
462
462
original_end = models .DateTimeField (("original end" ))
463
463
created_on = models .DateTimeField (("created on" ), auto_now_add = True )
464
464
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 )
466
466
467
467
class Meta :
468
468
verbose_name = ("occurrence" )
@@ -482,21 +482,22 @@ def __init__(self, *args, **kwargs):
482
482
def save (self , * args , ** kwargs ):
483
483
super ().save (* args , ** kwargs )
484
484
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
+ )
500
501
501
502
def moved (self ):
502
503
return self .original_start != self .start or self .original_end != self .end
0 commit comments