title: "Object has no property _set" in Django
body: <p>Can't figure out where my mistake is. Not able to map through to display the list of blog comments. I'm using Django and react. From the code below, I tried to assess each blog post with comments using foreign key. But I'm not able to get the comment property from the blog. If I do something like <code>{blog.title}</code> I get the title of the blog back on the browser. Since comments are associated with each post I try to get different properties of comment from the blog object (just as I specified in the code below) but the value I'm getting is <code>undefined</code>. And have the following blog post and blog comment models:</p>
  <pre class="lang-py prettyprint-override"><code>class BlogComment(models.Model):
      post = models.ForeignKey(BlogPost, on_delete=models.SET_NULL, related_name=&quot;post_comment&quot;,  null=True)
      user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, related_name=&quot;user_comment&quot;, null=True)
      name = models.CharField(max_length=200, null=True, blank=True)
      comment = models.TextField(null=True, blank=True)
      dateCreated = models.DateTimeField(auto_now_add=True)
  
      def __str__(self):
          return str(self.user.username)
  
  class BlogPost(models.Model):
      ...
      author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)
      body = models.TextField()
      dateCreated = models.DateTimeField(auto_now_add=True)
  </code></pre>
  <p>And the serializers for both models are:</p>
  <pre class="lang-py prettyprint-override"><code>class CommentSerializer(serializers.ModelSerializer):
      class Meta:
          model = BlogComment
          fields = '__all__'
  
  class BlogPostSerializer(serializers.ModelSerializer):
      comments = serializers.SerializerMethodField(read_only=True)
      class Meta:
          model = BlogPost
          fields = &quot;__all__&quot;
  
      def get_comments(self, obj):
          comments = obj.comment_set.all()
          serializer = CommentSerializer(comments, many=True)
          return serializer.data
  </code></pre>
  <p>The endpint of comment is <code>path('posts/&lt;str:pk&gt;/comment/', CreateCommentView, name=&quot;create-comment&quot;),</code>.</p>
  <p>The endpoint is working. I'm able to add comment to posts both from the front end. The error comes when I try to map through the
  comments for each post. Get the error: <code>AttributeError: 'BlogPost' object has no attribute 'comment_set'</code>.</p>
  <p>Here is the code I'm using to map through to display all the blogs of a particular post in the blog details page in react. I'm assess each blog there:</p>
  <pre class="lang-js prettyprint-override"><code>&lt;h2&gt;{blog.title}&lt;/h2&gt;
  &lt;img src={blog.image} /&gt;
  &lt;div variant='flush'&gt;
                      {blog.comments.map((comment) =&gt; (
                          &lt;div key={comment.id}&gt;
                              &lt;strong&gt;{comment.name}&lt;/strong&gt;            
                              &lt;p&gt;{comment.dateCreated}&lt;/p&gt;
                              &lt;p&gt;{comment.comment}&lt;/p&gt;
                          &lt;/div&gt;
                      ))}
                  &lt;/div&gt;
  
  </code></pre>
  <p>Here is the code I'm using to map through to display all the blogs of a particular post in the blog details page in react. If I do not map the error does not come up and I'm able to add comment. However, in order to display the comments under each blog post I map through. How do I fix this?</p>