title: how to identify and set User model foreign keys in User details database on submitting my User Registration form
body: <p>As I mentioned above I want to automatically identify the User's id from the User model and set it in my User details model as foreign key on Submitting Registration form curenty I am making changes manully to testing purpose which is not a practice for standalone website</p>
  <p><strong>models.py</strong></p>
  <pre><code>    class Student_Details(models.Model):
          u_id=models.ForeignKey(User,null=True,on_delete=models.SET_NULL)
          field=models.CharField(max_length=400,null=True)
      
      class Institute_Details(models.Model):
          I_id=models.ForeignKey(User,null=True,on_delete=models.SET_NULL)
          name=models.CharField(max_length=400,null=True)
          zipcode=models.CharField(max_length=6,null=True)
          def __str__(self):return str(self.name)
      
      class Staff_Details(models.Model):
          s_id=models.ForeignKey(User,null=True,on_delete=models.SET_NULL)
          Institute_from=models.ForeignKey(Institute_Details,null=True,on_delete=models.SET_NULL)
          def __str__(self):return str(self.s_id)
  </code></pre>
  <p><strong>form.py</strong></p>
  <pre><code>class CreateUserForm(UserCreationForm):
      class Meta:
          model = User
          fields = ['id','username','first_name','last_name','email', 'password1', 'password2']
  
  class Institute_form(ModelForm):
      class Meta:
          model = Institute_Details
          fields=['name','zipcode']
  </code></pre>
  <p><strong>viewspy</strong></p>
  <pre><code>@unauthenticated_user
  def registerPage(request):
      form = CreateUserForm()
      form2 = Institute_form(request.POST)
      if request.method == 'POST':
          form = CreateUserForm(request.POST)
          form2 = Institute_form(request.POST)
          if form.is_valid():
              if request.POST.get('user_type') == 'User':
                  user1 = form.save()
                  group1 = Group.objects.get(name='Student')
                  user1.groups.add(group1)
              elif request.POST.get('user_type') == 'Institute':
                  user2 = form.save()
                  form2.save()
                  group2 = Group.objects.get(name='Institute')
                  user2.groups.add(group2)
              return redirect('default')
  
      context = {'form': form,'Iform':form2}
      return render(request, &quot;htmls/signup.html&quot;, context)
  
  
  
  def logoutUser(request):
      logout(request)
      return redirect('default')
  </code></pre>