I have a function in the view file of Django Rest Framework project. Where it filters out comments (A model) with related to the specific Post
class CommentListCreate(APIView):
def get(self, request,pk):
comment = Comment.objects.filter(post_id=pk)
serializer = CommentSerializers(comment, many=True)
return Response(serializer.data)
The above function is able to filter according to the post_id, but if I change filter arguments as mention below
def get(self, request,pk):
comment = Comment.objects.filter(post__id=pk)
The function works fine, why do we use double underscore to refer the the post id ?
Git Link to my views.py https://github.com/Anoop-George/DjangoBlog/blob/master/blog/views.py