title: Change form fields based on request
body: <p>The application has a category field that may be set in the session and may not.  If it is, I don't want to see the field on the form just have it as a hidden field with the value equal to that in the request.  If it's not set then I want to display a dropdown.</p>
  
  <p>I've setup the form to include the dropdown, which is the default for this field and my question is, where is the best place to change the widget to hidden, bearing in mind I need the request so I can't do it in the forms <strong>init</strong>, which is the obvious place.</p>
  
  <p>Tried this approach, but the field remained visible:</p>
  
  <pre><code>class DocForm(forms.ModelForm):
  
  
      class Meta:
          model = Document
          fields = __all__
          widgets = {"creator": forms.HiddenInput(),}
  
      def __init__(self, *args, **kwargs):
          #cant do it here because don't have request
  
  class DocAddView(CreateView):
  
  
      form_class = DocForm
  
  
      def get_form_class(self):
          form_class = super(DocAddView, self).get_form_class()
          form_class.Meta.widgets['category'] = forms.HiddenInput()
          return form_class
  </code></pre>