title: Django: Prepopulate form field with foreign key
body: <p>In the process of creating my Django form I was wondering how to prepopulate a ForeignKey field with a default value?</p>
  
  <p>Imagine having the following model:</p>
  
  <pre><code>class Entity(models.Model):
      name = models.CharField(max_length=128)
      category = models.ForeignKey(Category)
      subtype = models.ForeignKey(Subtype)
      # field for subtype A
      fieldForA = models.CharField(max_length=20)
      # field for subtype B
      fieldForB = models.IntegerField()
  
  class Category(models.Model):
          name = models.CharField(max_length=128)
  
  class Subtype(models.Model):
      name = models.CharField(max_length=128)
      category = models.ForeignKey(Category)
  </code></pre>
  
  <p>For both subtypes I need a different view/form. So for subtype A I need to show 2 charfields whereas for subtype B I need to show a charfield and an integerfield. I also need to pre populate the foreignkey fields in advance, since I already know them. The form for subtype A I came up with looks like this:</p>
  
  <pre><code>class SubtypeACreateForm(forms.ModelForm):
      name = forms.CharField(max_length=128)
      category = forms.IntegerField(widget=forms.HiddenInput, initial=Category.objects.get(name='catForEntity')
      subtype = forms.IntegerField(widget=forms.HiddenInput, initial=Category.objects.get(name='a')
      fieldForA = forms.CharField(max_length=20)
  
      class Meta:
          model = Entity
                  exclude = ('fieldForB',)
  </code></pre>
  
  <p>Then on the way back I should be able find the correct model with the foreignkeys (integers). However, this does not looks like the best idea, also not very secure. What is the preferred way of pre populating somesort of ForeignKey field in a form? Any suggestions?</p>