title: How to pass user object to a Modelform using CreateView
body: <p><strong>NOT NULL constraint failed: blog_post.author_id</strong></p>
  
  <p>Hi, I'm fairly new to django and can't fix this error.</p>
  
  <p>I'm building a blog app and I want the author to be the current user.<br>
  I know that I'm not passing the user object to the form properly, but none of the solutions I found worked for me.</p>
  
  <p>Thank you in advance!</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class User(auth.models.User,auth.models.PermissionsMixin):
      def __str__(self):
          return '@{}'.format(self.username)
  
  
  class Post(models.Model):
      author = models.OneToOneField(User, on_delete=models.CASCADE)
      title = models.CharField(max_length=200)
      text = models.TextField()
  
  def get_absolute_url(self):
      return reverse('post_detail',kwargs={'pk':self.pk})
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class UserForm(UserCreationForm):
      class Meta:
          fields = ('username', 'email', 'password1', 'password2')
          model = get_user_model()
  
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
  
  
   class PostForm(forms.ModelForm):
       class Meta:
           model = Post
           fields = ('title', 'text',)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class SignUpView(CreateView):
      form_class = UserForm
      success_url = reverse_lazy('login')
      template_name = 'registration/signup.html'
  
  class PostCreateView(LoginRequiredMixin, CreateView):
      login_url = '/login/'
      redirect_field_name = 'blog/post_detail.html'
  
      form_class = PostForm
      model = Post
  </code></pre>