title: Django: How can I get the Foreign Key ID from selection on model form?
body: <p>Django beginner here. Say I have the following models:</p>
  
  <pre><code>    class Mom(models.Model):
          name = models.CharField(max_length=25)
  
      class Dad(models.Model):
          name = models.CharField(max_length=25)
  
      class Child(models.Model):
          name = models.CharField(max_length=25, unique=True)
          mom = models.ForeignKey(Mom)
          dad = models.ForeignKey(Dad)
  </code></pre>
  
  <p>Now say I have a form where I can select a combination of mom and dad and I want to generate a list of the kids they have together.</p>
  
  <pre><code>class ChildChooser(forms.ModelForm):
  
      class Meta:
          model = Child
          fields = ['mom', 'dad']
  </code></pre>
  
  <p>So I define a view:</p>
  
  <pre><code>def myChildChooserView(request):
      if request.method=='POST':
          form=ChildChooser(request.POST)
          if form.is_valid():
              myMom=form.cleaned_data['mom']
              myDad=form.cleaned_data['dad']
  
              return HttpResponseRedirect(reverse('kid-list', kwargs={'mom':myMom,                                                                               
                                                         'dad':myDad} ))
  
      else:
          form = RawYarnChooser()
  
          return render(request, 'chooser.html', {'form':form})
  </code></pre>
  
  <p>Which I was hoping could take advantage of a url I defined:</p>
  
  <pre><code>url(r'^kids/(?P&lt;mom&gt;[0-9]+)/(?P&lt;dad&gt;[0-9]+)/$',views.kidList, name='kid-list'),
  </code></pre>
  
  <p>The problem is that the URL needs the primary key of the 'mom' and 'dad' selected on the form. The form returns the text of the selection. What's the pythonic way to get the primary key numbers from the selection on the form so I can supply them to the kwargs of Http Response Redirect?</p>
  
  <p>The solution I have come up with is (in the view) to ping the database with something like:</p>
  
  <pre><code>mom_for_kwargs=Mom.objects.get(name=myMom)
  dad_for_kwargs=Dad.objects.get(name=myDad)
  </code></pre>
  
  <p>And then get the id from those. But this seems to be a very roundabout way to do it. Just wondering if there is a better way.</p>
  
  <p>Thanks!</p>