title: Update instances of ModelFormset
body: <p>In my django app two models are connecetd by <code>manytomany</code> relation and I am using <code>modelformset_fatory</code> to create a form like this </p>
  
  <p>Views.py</p>
  
  <pre><code>def post(request):
      tform = TeamForm()
      pform = modelformset_factory(Player, form=PlayerForm, extra = 1)
      pform = pform(request.POST or None, queryset = Player.objects.filter(id__isnull = True))
      if request.method == 'POST':
          t = Team()
          tform = TeamForm(request.POST, instance=t)
          if tform.is_valid() and pform.is_valid():
              tform.save()
              instances = pform.save(commit=False)
              for i in instances:
                  player = Player()
                  player.pname = i.pname
                  player.hscore = i.age
                  player.age = i.hscore
                  player.save()
                  t.player.add(player)
              t.save()
              return redirect('/exams/dashboard/')
          else:
              print('invalid data')
      return render(request, 'team/team_create.html', {'exform': tform, 'exformset': pform})
  </code></pre>
  
  <p>This is working perfectly fine but the problem occurs when I try to update the form, I am able to initialize the form with the data but when I create a new <code>player</code> instance in form it does not get saved.</p>
  
  <p>Update function:</p>
  
  <pre><code>def update(request, pk = None):
      team = Team.objects.get(id = pk)
      tform = TeamForm(instance = team)
      pform = modelformset_factory(Player, form=PlayerForm, extra=0)
      print("players", Player.objects.filter(team=team))
      pform = pform(request.POST or None, queryset=Player.objects.filter(team=team))
      if request.method == 'POST':
          tform = TeamForm(request.POST, instance=team)
          print("tform ", tform)
          print("pform ", pform)
          if tform.is_valid() and pform.is_valid():
              tform.save()
              pform.save()
              return redirect('/exams/dashboard/')
          else:
              print('invalid data')
      return render(request, 'team/team_create.html', {'exform': tform, 'exformset': pform})
  </code></pre>
  
  <p>Do I have to rewrite the following:</p>
  
  <pre><code>instances = pform.save(commit=False)
              for i in instances:
                  player = Player()
                  player.pname = i.pname
                  player.hscore = i.age
                  player.age = i.hscore
                  player.save()
                  t.player.add(player)
              t.save()
  </code></pre>
  
  <p>If yes, then wouldn't it create new enteries rather than updating the old ones?</p>