title: Deleting an object field before saving using django forms
body: <p>The following code uses a form to save a new user avatar picture, however I cannot get this to delete the delete the old avatar and update with the new on. I've tried many different code variations.</p>
  
  <p>Could someone point me in the correct direction. An explanation on why this is happening and brief example would be very helpful. All help is greatly appreciated.</p>
  
  <p>model</p>
  
  <pre><code>class Profile(models.Model):
  user = models.ForeignKey('auth.User')
  avatar = Image..................
  </code></pre>
  
  <p>view</p>
  
  <pre><code>@login_required
  def profile(request, pk):
      profile = Profile.objects.get(user=pk)
      pf = ProfileForm(request.POST, request.FILES, instance=profile)
      if request.method =="POST":
          if pf.is_valid():
              profile.avatar.delete() #doesn't work
              pf.save()
  
      return render_to_response('template.html', {
          'profile': profile,
          'pf':pf
      }, context_instance=RequestContext(request))
  </code></pre>
  
  <p>template</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="" method="POST"&gt; {% csrf_token %}
      {{ pf }}
      &lt;input type="submit" value="Submit" id="submit" /&gt;
  &lt;/form&gt;
  </code></pre>