title: get_or_create for two related models and formsets
body: <p>I have two models related by a ForeignKey and inline formsets:</p>
  
  <pre><code>class Balanta(models.Model):
      data = models.DateField()
  
      class Meta:
          ordering=['data']
          verbose_name_plural="Balante"
  
      def __unicode__(self):
          return unicode(self.data)
  
  class Conturi(models.Model):
      cont=models.PositiveIntegerField()
      cont_debit=models.DecimalField(default=0, max_digits=30, decimal_places=2)
      cont_credit=models.DecimalField(default=0, max_digits=30, decimal_places=2)
      balanta = models.ForeignKey(Balanta)
  
      class Meta:
          #oredering=['cont']
          verbose_name_plural="Conturi"
  
      def __unicode__(self):
          return unicode(self.cont)
  </code></pre>
  
  <p>I have formsets based on the two models. After i submit the form, if the "Balanta part of the form" exists, the form shouldn't do anything an dif it doesn't exists it should save it in the database (I managed to do this).</p>
  
  <p>Now what i want to do on the "Conturi part of the form" is to see if the cont is on the database, the form should update it with the value in the input box and if it is not in the db, the form should create it and the corresponding cont_debit or cont_credit. The current state gives me: get_or_create() argument after ** must be a mapping, not list.</p>
  
  <p>I think is something bigger then mt simple/newbie way to solve the problem.</p>
  
  <p>Here is the view:</p>
  
  <p>*<strong><em>LAST UPDATE</em>*</strong></p>
  
  <pre><code>from django.http import HttpResponseRedirect
  from django.shortcuts import get_object_or_404, render_to_response
  from django.template import RequestContext
  from sitfin.models import Balanta, Conturi
  from sitfin.forms import BalantaForm , ConturiForm
  from django.forms.models import inlineformset_factory
  
  def balanta_introducere(request):
      balanta=Balanta()
      ConturiInlineFormSet=inlineformset_factory(Balanta, Conturi, extra=3)
      if  request.method=='POST':
          balanta_form=BalantaForm(request.POST, instance=balanta)
          if balanta_form.is_valid():
              balanta, created=Balanta.objects.get_or_create(**balanta_form.cleaned_data)
              #return HttpResponseRedirect('/sitfin/balantaok')
          formset=ConturiInlineFormSet(request.POST, request.FILES, instance=balanta)
          if formset.is_valid():
              #formset.save()
              for form in formset:
                  data={
                          'cont':form.cleaned_data.get('cont'),
                          'cont_debit':form.cleaned_data.get('cont_debit'),
                          'cont_credit':form.cleaned_data.get('cont_credit'),
                          'balanta':form.cleaned_data.get('balanta'),
                  }
                  try:
                      c=Conturi()#.objects.get(cont=data['cont'])
                  except Conturi.DoesNotExist:
                      cont_complete,created=Conturi.objects.get_or_create(**data)
                  else:
                      for form in formset:
                          new_data={
                                  'cont':form.cleaned_data.get('cont'),
                                  'cont_debit':form.cleaned_data.get('cont_debit'),
                                  'cont_credit':form.cleaned_data.get('cont_credit'),
                                  'balanta':form.cleaned_data.get('balanta'),
                          }
                          cont_complete,created=Conturi.objects.get_or_create(**new_data)
      else:
          balanta_form=BalantaForm()
          formset=ConturiInlineFormSet(instance=balanta)
      return render_to_response('sitfin/balanta_introducere.html',{'balanta_form':balanta_form,'formset':formset}, context_instance=RequestContext(request))
  </code></pre>