title: Django passing user ID to filter models
body: <p>I have trying to filter objects in a model to avoid people putting events in their calendars which over lap. I found the below link which helped (<a href="https://stackoverflow.com/questions/13026689/django-form-field-clean-to-check-if-entered-date-is-in-a-stored-range">Django form field clean to check if entered date is in a stored range</a>). It has left me with another issue that it blocks any other user from having an event at the same time.</p>
  <p>My Question is, can I pass the user id number to filter the queryset? it works if I manually input my user ID number?</p>
  <p>Code below with my last attempt?</p>
  <p>model.py</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  class Event(models.Model):
      manage = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
      title = models.CharField(max_length=200, default='free')
      description = models.TextField()
      start_time = models.DateTimeField()
      end_time = models.DateTimeField()
  
      def __str__(self):
          return self.title + &quot; - &quot; + str(self.start_time) + &quot; - &quot; + str(self.end_time)
  </code></pre>
  <p>Form.py</p>
  <pre><code>from django import forms
  from django.forms import ModelForm, DateInput
  from calendar_app.models import Event
  from django.contrib.auth.models import User
  
  
  
  class EventForm(ModelForm):
    class Meta:
      model = Event
      # datetime-local is a HTML5 input type, format to make date time show on fields
      widgets = {
        'start_time': DateInput(attrs={'type': 'datetime-local'}, format='%Y-%m-%dT%H:%M'),
        'end_time': DateInput(attrs={'type': 'datetime-local'}, format='%Y-%m-%dT%H:%M'),
      }
      fields = ['title','description','start_time','end_time']
  
    def __init__(self, *args, **kwargs):
      super(EventForm, self).__init__(*args, **kwargs)
      # input_formats parses HTML5 datetime-local input to datetime field
      self.fields['start_time'].input_formats = ('%Y-%m-%dT%H:%M',)
      self.fields['end_time'].input_formats = ('%Y-%m-%dT%H:%M',)
  
  
    def clean(self):
      form_start_time = self.cleaned_data.get('start_time')
      form_end_time = self.cleaned_data.get('end_time')
      form_manage = self.cleaned_data.get('manage')
      between = Event.objects.filter(manage=form_manage, start_time__gte=form_start_time, end_time__lte=form_end_time)
      if between:
        raise forms.ValidationError('Already Calendar entry for this time')
      super(EventForm,self).clean()
  </code></pre>
  <p>views.py</p>
  <pre><code>def event(request, event_id=None):
      instance = Event()
      if event_id:
          instance = get_object_or_404(Event, pk=event_id)
      else:
          instance = Event()
      
      form = EventForm(request.POST or None, instance=instance)
      if request.POST and form.is_valid():
          instance.manage = request.user
          form.save()
          return HttpResponseRedirect(reverse('calendar_app:calendar'))
      return render(request, 'event.html', {'form': form})
  </code></pre>