title: Retaining uploaded file (FileField) when form is not valid
body: <p>Given a Model with a required field called <code>number</code> and a <a href="https://docs.djangoproject.com/en/dev/ref/forms/widgets/#clearablefileinput" rel="nofollow noreferrer">ClearableFileInput</a> FileField called <code>upload_file</code>:</p>
  
  <pre><code>class ExampleModel(models.Model):
      number = models.IntegerField()
      upload_file = models.FileField(blank=True, null=True)
  </code></pre>
  
  <p>In my view, on POST, if the form <code>is_valid</code> then I can populate the <em>clearable</em> part of the FileField when returning to the same page.</p>
  
  <pre><code>def example_view(request):
      context = RequestContext(request)
      if request.method == 'POST':
          form = ExampleForm(request.POST, request.FILES)
          if form.is_valid():
              form_instance = form.save()
              form = ExampleForm(instance=form_instance)
              # or alternatively, for just the upload file field
              form = ExampleForm(initial={'upload_file': form_instance.upload_file})
          else:
              form_instance = form.save(commit=False)
              form = ExampleForm(initial={'upload_file': form_instance.upload_file})
              # unfortunately, this also does not work:
              form = ExampleForm(initial={'upload_file': form.fields['upload_file']})
      else:
          form = ExampleForm()
  return render_to_response('enterrecords/example.html', {'form': form}, context) 
  </code></pre>
  
  <p>This is how it looks:</p>
  
  <p><a href="https://i.stack.imgur.com/tx3Ku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tx3Ku.png" alt="Django ClearableFileInput"></a></p>
  
  <p>However, if the form is not valid (see first else case), I can not <code>form.save(commit=False)</code> and therefore cannot populate the <em>clearable</em> part of the FileField.</p>
  
  <p>The <code>form.save(commit=False)</code> gives the following error:</p>
  
  <pre><code>ValueError at /en/myapp/example/
  The ExampleModel could not be created because the data didn't validate.
  </code></pre>
  
  <p><strong>Is there a workaround for this problem?</strong></p>
  
  <p>For completeness...</p>
  
  <p>ModelForm</p>
  
  <pre><code>class ExampleForm(forms.ModelForm):
      class Meta:
          model = ExampleModel
  </code></pre>
  
  <p>Template</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" method="POST" action="{% url 'eg' %}"&gt;
      {% csrf_token %}
      {{ form.as_p }}
      &lt;button type="submit" name="next" value="Next" /&gt;Next&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>