from .models import BlogPost, BlogComment
from django.forms import ModelForm

class BlogPostForm(ModelForm):
    class Meta:
        model = BlogPost
        exclude = ('user',)

    def save(self, user, commit=True):
        post = super(BlogPostForm, self).save(commit=False)
        post.user = user

        if commit:
            post.save()
        return post

class CommentForm(ModelForm):
    class Meta:
        model = BlogComment
        exclude = ('post', 'user',)

from .models import BlogPost, BlogComment
from django.forms import ModelForm

class BlogPostForm(ModelForm):
    class Meta:
        model = BlogPost
        exclude = ('user',)

    def save(self, user, commit=True):
        post = super(BlogPostForm, self).save(commit=False)
        post.user = user

        if commit:
            post.save()
        return post

class CommentForm(ModelForm):
    class Meta:
        model = BlogComment
        exclude = ('post', 'user',)

    def save(self, user, post, commit=True):
        comment = super(CommentForm, self).save(commit=False)
        comment.user = user
        comment.post = post

        if commit:
            comment.save()
        return comment

Add a custom save() method to CommentForm
Add a custom save() method to CommentForm

  from .models import BlogPost, BlogComment
  from django.forms import ModelForm
  
  class BlogPostForm(ModelForm):
      class Meta:
          model = BlogPost
          exclude = ('user',)
  
      def save(self, user, commit=True):
          post = super(BlogPostForm, self).save(commit=False)
          post.user = user
  
          if commit:
              post.save()
          return post
  
  class CommentForm(ModelForm):
      class Meta:
          model = BlogComment
          exclude = ('post', 'user',)
  
+     def save(self, user, post, commit=True):
+         comment = super(CommentForm, self).save(commit=False)
+         comment.user = user
+         comment.post = post
+ 
+         if commit:
+             comment.save()
+         return comment
+ 
Add a custom save() method to CommentForm
## Code Before:
from .models import BlogPost, BlogComment
from django.forms import ModelForm

class BlogPostForm(ModelForm):
    class Meta:
        model = BlogPost
        exclude = ('user',)

    def save(self, user, commit=True):
        post = super(BlogPostForm, self).save(commit=False)
        post.user = user

        if commit:
            post.save()
        return post

class CommentForm(ModelForm):
    class Meta:
        model = BlogComment
        exclude = ('post', 'user',)

## Instruction:
Add a custom save() method to CommentForm
## Code After:
from .models import BlogPost, BlogComment
from django.forms import ModelForm

class BlogPostForm(ModelForm):
    class Meta:
        model = BlogPost
        exclude = ('user',)

    def save(self, user, commit=True):
        post = super(BlogPostForm, self).save(commit=False)
        post.user = user

        if commit:
            post.save()
        return post

class CommentForm(ModelForm):
    class Meta:
        model = BlogComment
        exclude = ('post', 'user',)

    def save(self, user, post, commit=True):
        comment = super(CommentForm, self).save(commit=False)
        comment.user = user
        comment.post = post

        if commit:
            comment.save()
        return comment
