title: Django - automatically create a model instance when another model instance is created
body: <p>I have an overrided User model and a Cart model. I expect that a Cart model instance is created automatically once a User model instance is created. I am trying to pass the newly registered user into the <code>get_queryset</code> method, but no idea how to do it. Are there any other better ways of doing this? It's because I may need to do the same thing for other models unlike the User model which has a form that can pass values to the <code>get_queryset</code> method.</p>
  
  <p><strong>account/models.py:</strong></p>
  
  <pre><code>class Cart(models.Model):
  
      user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
  
      def __str__(self):
          return self.user.email + '_cart'
  </code></pre>
  
  <p><strong>account/views.py:</strong></p>
  
  <pre><code>class RegisterView(generic.CreateView):
      template_name = 'account/register.html'
      form_class = RegisterForm
      success_url = reverse_lazy('book:home')
  
      def get_queryset(self):
          sign_up = self.request.POST.get('register')
          if sign_up:
              c = Cart.objects.create(user=???)
              c.save()
  </code></pre>
  
  <p><strong>account/templates/account/register.html:</strong></p>
  
  <pre><code>&lt;form name="register" method="post"&gt;{% csrf_token %}
      {{ form.as_p }}
      &lt;input type="submit" value="Sign Up"&gt;
  &lt;/form&gt;
  </code></pre>