title: How to use the request in a ModelForm in Django
body: <p>I would like to make a queryset where the current user is used as a filter in a ModelForm:</p>
  
  <pre><code>class BookSubmitForm(ModelForm):
      book = forms.ModelChoiceField(queryset=Book.objects.filter(owner=request.user),)
  ...
  </code></pre>
  
  <p>Does Django pass the request to the form? Is it good practice? How can I use the request? (of course the name request is not defined)</p>
  
  <p>Edit:</p>
  
  <p>I tried another solution which is to call the form in the view passing it the request:</p>
  
  <pre><code>form = BookSubmitForm(request)
  </code></pre>
  
  <p>and then in the form I use this:</p>
  
  <pre><code>class BookSubmitForm(ModelForm):
      def __init__(self, request, *args, **kwargs):
          super(BookSubmitForm, self).__init__(*args, **kwargs)
          self.fields["library"].queryset = Library.objects.filter(owner=request.user)
  </code></pre>
  
  <p>It works and the code is in the form. Now I'm not sure it's the best solution, could it be improved?</p>