How To Nest These Serializes Without Facing Attributeerror: 'blogpost' Object Has No Attribute 'review_set'
I followed Dennis Ivy proshop Tutorial He used the same approach as the code is class ReviewSerializer(serializers.ModelSerializer): class Meta: model = Review
Solution 1:
The simplest solution is to update your get_blog_post_reviews
method:
defget_blog_post_reviews(self, obj):
blog_post_reviews = obj.blogpostreview_set.all() # <- this line has changed
serializer = BlogPostReviewSerializer(blog_post_reviews, many=True)
return serializer.data
The original worked because there was a model named Review
, so the automatically created reverse name was review_set
. Your model is named BlogPostReview
, so the reverse is blogpostreview_set
.
More information about reverse relationships in the docs.
Post a Comment for "How To Nest These Serializes Without Facing Attributeerror: 'blogpost' Object Has No Attribute 'review_set'"