title: Automatically create a model when another with ForeignKey is created
body: <p>I'm trying to create a registration process where a certain model (Member) is automatically created when I create the model UserFields, but I'm unable to find a solution; this is what I tried:</p>
  <p><strong>Models.py</strong></p>
  <pre><code>class Member(models.Model):
      member_id = models.AutoField(primary_key=True)
      user_creation_date = models.DateField(auto_now_add=True)
  
  class MemberType(models.Model):
      type_name = models.CharField(max_length=255, primary_key=True)
      member_type = models.ForeignKey(Member, on_delete=models.CASCADE)
  
  class MemberFields(models.Model):
      member = models.ForeignKey(Member, on_delete=models.CASCADE)
      social_security_id = models.CharField(max_length=255)
      first_name = models.CharField(max_length=255)
      last_name = models.CharField(max_length=255)
      birth_date = models.DateField()
      birthplace = CountryField()
      gender = models.CharField(choices=GENDER_CHOICES, max_length=255)
      admission_date = models.DateField()
  </code></pre>
  <p><strong>Forms.py</strong></p>
  <pre><code>class MemberFieldsForm(forms.ModelForm):
      class Meta:
          model = MemberFields
          fields = [
              &quot;social_security_id&quot;,
              &quot;first_name&quot;,
              &quot;last_name&quot;,
              &quot;birth_date&quot;,
              &quot;birthplace&quot;,
              &quot;gender&quot;,
              &quot;admission_date&quot;,
          ]
          labels = {
              &quot;social_security_id&quot;: &quot;SSN&quot;,
              &quot;first_name&quot;: &quot;First name&quot;,
              &quot;last_name&quot;: &quot;Last name&quot;,
              &quot;birth_date&quot;: &quot;Date of birth&quot;,
              &quot;birthplace&quot;: &quot;Place of birth&quot;,
              &quot;sex&quot;: &quot;Sex&quot;,
              &quot;address&quot;: &quot;Address&quot;,
              &quot;admission_date&quot;: &quot;Admission date&quot;,
          }
          widgets = {
              &quot;member_type&quot;: forms.TextInput(attrs={'class': 'form-control'}),
              &quot;social_security_id&quot;: forms.TextInput(attrs={'class': 'form-control'}),
              &quot;first_name&quot;: forms.TextInput(attrs={'class': 'form-control'}),
              &quot;last_name&quot;: forms.TextInput(attrs={'class': 'form-control'}),
              &quot;birth_date&quot;: forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
              &quot;birthplace&quot;: forms.Select(attrs={'class': 'form-control'}),
              &quot;address&quot;: forms.Select(attrs={'class': 'form-control'}),
              &quot;sex&quot;: forms.Select(attrs={'class': 'form-control'}),
              &quot;admission_date&quot;: forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
              &quot;member_type&quot;: forms.Select(attrs={'class': 'form-control'}),
          }
  </code></pre>
  <p><strong>Views.py</strong></p>
  <pre><code>def index(request):
      if request.method == 'POST':
          form = MemberFieldsForm(request.POST)
          if form.is_valid():
              c = form.changed_data[&quot;Member&quot;]
              member = Member.objects.filter(name=c).first()
              if not member:
                  member = Member.objects.create(name=c)
              MemberFields = form.save(commit=False)
              MemberFields.Member = Member
              MemberFields.save()
              return HttpResponse(&quot;Member registered&quot;)
      else:
          form = MemberFieldsForm()
      return render(request, 'add-member.html', {'form': form})
  </code></pre>
  <p>I don't know if it's the right way to do it, I'm new to Django and Python and there are many things that are still unclear to me.</p>
  <p>Thanks in advance!</p>