title: Set initial values in form passing parameters (kwargs) with view
body: <p>I want to prefill a form with values taken in a table.
  First I pass the PK relative to the line where I wan't to get values and build the kwargs list:</p>
  <p><strong>views.py</strong></p>
  <pre><code>def NavetteToFicheCreateView(request, pk):
  
      navette = Navette.objects.get(id=pk)
      ref = navette.id
      attribute_set = navette.famille.pk
      cost = navette.cost
      qty = navette.qty
      etat = navette.etat
      etat_ebay = navette.etat.etat_ebay
      ean = get_last_ean()
  
      form = NavetteToFicheForm(
          request.POST,
          ref=ref,
          attribute_set=attribute_set,
          cost=cost,
          qty=qty,
          etat=etat,
          etat_ebay=etat_ebay,
          ean=ean,
  )
  [...]
  </code></pre>
  <p>then I retrieve the kwargs in the <strong>form.py</strong> and setup my initial values</p>
  <p>class NavetteToFicheForm(forms.ModelForm):</p>
  <pre><code>def __init__(self, *args, **kwargs):
  
      self.ref = kwargs.pop('ref', 'noref')
      self.attribute_set = kwargs.pop('attribute_set', 9999)
      self.cost = kwargs.pop('cost', 0)
      self.qty = kwargs.pop('qty', 0)
      self.etat = kwargs.pop('etat', 0)
      self.etat_ebay = kwargs.pop('etat_ebay', 9999)
      self.ean = kwargs.pop('ean', 9999)
  
      super(NavetteToFicheForm, self).__init__(*args, **kwargs)
  
      self.fields['ref'].initial = self.ref
      self.fields['attribute_set'].initial = self.attribute_set
      self.fields['cost'].initial = self.cost
      self.fields['qty'].initial = self.qty
      self.fields['etat'].initial = self.etat
      self.fields['etat_ebay'].initial = self.etat_ebay
      self.fields['ean'].initial = self.ean
  [...]
  </code></pre>
  <p>My problem : some fields like &quot;ref&quot; or &quot;attribute_set&quot; are foreignKeys and are not transmitted when i display the form.</p>
  <p>For checking my values :</p>
  <pre><code>print(self.ref)
  print(self.attribute_set)
  </code></pre>
  <p><strong>output</strong></p>
  <pre><code>34
  2
  noref
  9999
  </code></pre>
  <p>questions :</p>
  <ol>
  <li><p>Why does the &quot;print&quot; displays 2 couples of values ? This looks like as if the &quot;noref&quot; and &quot;999&quot; are taken in account.</p>
  </li>
  <li><p>Why if i set manually 34 and 2 values, it works ?</p>
  <p>self.fields['ref'].initial = 34
  self.fields['attribute_set'].initial = 2</p>
  </li>
  </ol>
  <p>There's maybe a better way of doing this but I don't know it yet .</p>