title: Django - get user id after saving the user
body: <p>I'm working on a project using Python(3.7) and Django(2.2) in which I have implemented models for multiple type of users and combined models by using <code>MultiModleForm</code> to display as a single form on front end, after that when I try to create a user in view and call the save method for <code>user</code> model and try to get its <code>id</code> but it's giving an error.</p>
  
  <p>Here's what I have tried so far:</p>
  
  <p>From <code>models.py</code>:</p>
  
  <pre><code>class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(max_length=254, unique=True)
      title = models.CharField(max_length=255, blank=False)
      user_type = models.CharField(max_length=255, choices=USER_TYPE, blank=False)
      gender = models.CharField(max_length=255, choices=CHOICES, blank=False)
      contenst = models.CharField(max_length=255, blank=True)
      is_staff = models.BooleanField(default=False)
      is_superuser = models.BooleanField(default=False)
      is_active = models.BooleanField(default=True)
      last_login = models.DateTimeField(null=True, blank=True)
      date_joined = models.DateTimeField(auto_now_add=True)
  
      USERNAME_FIELD = 'email'
      EMAIL_FIELD = 'email'
      REQUIRED_FIELDS = ['password']
  
      objects = UserManager()
  
      def get_absolute_url(self):
          return "/users/%i/" % (self.pk)
  
  class Parent(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      contact_email = models.EmailField(blank=False)
      customer_id = models.BigIntegerField(blank=False)
      contact_no = PhoneNumberField(blank=True, help_text='Phone number must be entered in the'
                                                          'format: \'+999999999\'. Up to 15 digits allowed.')
      collection_use_personal_data = models.BooleanField(blank=False)
  </code></pre>
  
  <p><strong>From <code>forms.py</code>:</strong></p>
  
  <pre><code>class ParentForm(forms.ModelForm):
  
      class Meta:
          model = Parent
          fields = ('contact_email', 'contact_no', 'collection_use_personal_data')
  
  
  class UserParentForm(MultiModelForm):
      form_classes = {
          'user': UserForm,
          'profile': ParentForm
      }
  </code></pre>
  
  <p><strong>From <code>views.py</code>:</strong></p>
  
  <pre><code>def post(self, request, *args, **kwargs):
      print(request.POST)
      user_type = request.POST.copy()['user-user_type']
      form = None
      if user_type == 'PB':
          form = UserBelow18Form(request.POST)
      elif user_type == 'PA':
          form = UserAbove18Form(request.POST)
      elif user_type == 'Parent':
          form = UserParentForm(request.POST)
          print('user-parent form selected')
      elif user_type == 'GC':
          form = UserGCForm(request.POST)
  
      if form.is_valid():
          user = form['user']
          profile = form['profile']
          if user_type == 'Parent' or user_type == 'GC':
              c_id = generate_cid()
              profile.customer_id = c_id
              print('id generated for parent or GC: {}'.format(c_id))
  
              try:
                  user.save()
                  profile.user = User.objects.get(id=user.id)
                  # print(user_obj.email)
                  # profile.user = user_obj.id
                  profile.save()
                  print(user.email)
                  return HttpResponseRedirect(reverse_lazy('users:login'))
              except Exception as e:
                  return HttpResponse('something as: {}'.format(e))
  </code></pre>
  
  <p>But I'm getting the error as:</p>
  
  <blockquote>
    <p>something as: 'UserForm' object has no attribute 'id'</p>
  </blockquote>