which i have a model called Qusetion
and another model called Answer
class Qustion(models.Model):
user = models.ForeighnKey(User)
content = models.CharField(max_length=100)
title= models.CharField(max_length=100)
class Answer(models.Model):
question = models.ForeignKey(Question on_delete=models.CASCADE)
content = models.IntegerField()
date = models.TimeField()
user = models.ForeighnKey(User)
expected output like this
[
{
"id": 2,
"content": "this is first post comment",
"comment": [
{
"user": {
"id": 1,
"username": "m_mohamed",
},
"content": "this is first comment",
"date": "2017-05-14T21:40:48.123368Z"
}
],
"publish_user": {
"id": 2,
"username": "H_mohamed",
}
Ok, you better ask in a proper DRF forum (not opening an issue) or read more docs (this is explained on DRF docs), this is not the place for asking about nested serializers.
@angvp @shanx @kvbik anyone help
which i have a model called Qusetion and another model called Answer
class Qustion(models.Model): user = models.ForeighnKey(User) content = models.CharField(max_length=100) title= models.CharField(max_length=100)
class Answer(models.Model): question = models.ForeignKey(Question on_delete=models.CASCADE) content = models.IntegerField() date = models.TimeField() user = models.ForeighnKey(User)
expected output like this
[ { "id": 2, "content": "this is first post comment", "comment": [ { "user": { "id": 1, "username": "m_mohamed", }, "content": "this is first comment", "date": "2017-05-14T21:40:48.123368Z" } ], "publish_user": { "id": 2, "username": "H_mohamed", }
]
}