old_contents: import datetime
  from django.forms import ModelForm, ValidationError, widgets
  from django.shortcuts import get_object_or_404
  from reservations.models import Queue, Reservation
  
  
  class QueueForm(ModelForm):
  
      class Meta:
          model = Queue
          fields = '__all__'
  
  
  class ReservationForm(ModelForm):
  
      class Meta:
          model = Reservation
          fields = ('date', 'start_time', 'end_time', )
  
      def __init__(self, *args, **kwargs):
          self.parent_queue = get_object_or_404(Queue, pk=kwargs.pop('pk'))
          super().__init__(*args, **kwargs)
  
      def clean(self):
          start_time = self.cleaned_data.get('start_time', None)
          end_time = self.cleaned_data.get('end_time', None)
          date = self.cleaned_data.get('date', None)
  
          if start_time > end_time:
              raise ValidationError("Invalid argument parameters")
  
          if date < datetime.date.today():
              raise ValidationError("You cannot make reservations back in time")
  
          for interval in [(r.start_time, r.end_time) for r in self.parent_queue.reservations.filter(date=date)]:
              reservation_overlap = interval[0] <= start_time, end_time <= interval[1]
              if reservation_overlap.__contains__(True):
                  raise ValidationError("Reservation incompatible with existing reservations")
  
new_contents: import datetime
  from django.forms import ModelForm, ValidationError, widgets
  from django.shortcuts import get_object_or_404
  from reservations.models import Queue, Reservation
  
  
  class QueueForm(ModelForm):
  
      class Meta:
          model = Queue
          fields = '__all__'
  
  
  class ReservationForm(ModelForm):
  
      class Meta:
          model = Reservation
          fields = ('date', 'start_time', 'end_time', )
  
      def __init__(self, *args, **kwargs):
          self.parent_queue = get_object_or_404(Queue, pk=kwargs.pop('pk'))
          super().__init__(*args, **kwargs)
  
      def clean(self):
          start_time = self.cleaned_data.get('start_time', None)
          end_time = self.cleaned_data.get('end_time', None)
          date = self.cleaned_data.get('date', None)
  
          if start_time > end_time:
              raise ValidationError("Invalid argument parameters")
  
          if date < datetime.date.today() or start_time < (datetime.datetime.now() - datetime.timedelta(minutes=5)):
              raise ValidationError("You cannot make reservations back in time")
  
          for interval in [(r.start_time, r.end_time) for r in self.parent_queue.reservations.filter(date=date)]:
              reservation_overlap = interval[0] <= start_time, end_time <= interval[1]
              if reservation_overlap.__contains__(True):
                  raise ValidationError("Reservation incompatible with existing reservations")
  
subject: stop reservations beginning more than 5 minutes ago