-
Notifications
You must be signed in to change notification settings - Fork 299
Closed
Description
Hi, all!
I have the following Django model:
class Comment(model.Model):
text = models.TextField()
parent_comment = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
I want to be able to obtain a list of comments with "parent" in relationships, for example:
{
"data": [
{
"type": "comments",
"id": "1",
"attributes": {
"text": "First comment"
},
"relationships": {
"parent": {
"data": null
}
}
},
{
"type": "comments",
"id": "2",
"attributes": {
"text": "Child comment"
},
"relationships": {
"parent": {
"data": {
"type": "comments",
"id": 1
}
}
}
},
]
}
My serializer:
class CommentSerializer(ModelSerializer):
parent = ResourceRelatedField(source='parent_comment', read_only=True)
class Meta:
model = Comment
fields = ('text', 'parent',)
In my ViewSet I have defined resource_name = 'comments', but it is doesn't work for "parent" in relationships. At the present time, "type" of "parent" is "Comment". How can I fix this issue?
Metadata
Metadata
Assignees
Labels
No labels