title: Django ModelForm to update profile picture does not save the photo
body: <p>I want to enable my users to change their profile picture. When uploading a photo, I am redirected to the success page but the photo is not uploaded to the folder and the associated field is blank. Note that if a user already had a photo, it resets the field to blank so after submitting the form, the user has no photo anymore.</p>
  
  <p>My guess is that the form.save(commit=False) does not upload the photo nor update the field as it should but I do not understand why !</p>
  
  <p>Here is the model, view and form :</p>
  
  <p>The Profil model:</p>
  
  <pre><code>class Profil(models.Model):
  user=models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
  photo_profil=models.ImageField(null=True,blank=True,upload_to='img/profils', verbose_name="Photo de profil", help_text="La taille du fichier doit être inférieure à {0}Mo. Seules les extensions .png, .jpeg et .jpg sont acceptées.".format(str(int(MAX_UPLOAD_SIZE/1000000))))
  cours_valides=models.CharField(blank=True,max_length=255,validators=[int_list_validator])
  niveau_valides=models.CharField(blank=True,max_length=255,validators=[int_list_validator])
  
  def __str__(self):
      return "Profil de {0}".format(self.user.username)
  </code></pre>
  
  <p>The ModelForm:</p>
  
  <pre><code>class PhotoForm(forms.ModelForm):
  class Meta:
      model=models.Profil
      fields=('photo_profil',)
  def clean_photo(self):
      photo=self.cleaned_data.get('photo_profil')
      if photo.size&gt;settings.MAX_UPLOAD_SIZE:
          raise forms.ValidationError(_("Le fichier envoyé depasse la limite de %sMo.".format(str(settings.MAX_UPLOAD_SIZE/1000000))))
      return photo
  </code></pre>
  
  <p>And the view :</p>
  
  <pre><code>@login_required()
  def change_photo(request):
      if request.method=="POST":
          form=forms.PhotoForm(request.POST,request.FILES)
          if form.is_valid():
              profil=form.save(commit=False)
              profil.user=request.user
              profil.save()
              return redirect('espace_personnel')
      else:
          form=forms.PhotoForm()
      return render(request,'utilisateurs/registration/change_photo.html',{'form':form})
  </code></pre>
  
  <p>Finally the template:</p>
  
  <pre><code>{% block item %}
      &lt;h3&gt; Modifier sa photo de profil &lt;/h3&gt;
      &lt;hr&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-lg-4"&gt;
              &lt;img src="{{user.profil.photo_profil_url}}" alt="{{user.username}}" class="img-responsive"/&gt;
          &lt;/div&gt;
          &lt;div class="col-lg-8"&gt;
              &lt;h5&gt;Photo actuelle&lt;/h5&gt;
              &lt;p class="text-justify"&gt; Votre photo n'est visible pour les autres utilisateurs qu'à côté des commentaires que vous laissez sur le site.&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;hr&gt;
      &lt;form method="post"&gt;
      {% csrf_token %}
      &lt;div class="form-group"&gt;
          {{form.photo_profil}}
      &lt;/div&gt;
      &lt;p class="alert alert-info"&gt;{{form.photo_profil.help_text}}&lt;/p&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Envoyer&lt;/button&gt;
      &lt;/form&gt;
      &lt;hr&gt;
  {% endblock item %}
  </code></pre>
  
  <p>I have a read a few topics already but without success.</p>
  
  <p>Thank you in advance for your help,</p>
  
  <p>Matthieu</p>