jpadilla / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-jwt/
MIT License
3.19k stars 652 forks source link

How to make nested Serializer #333

Closed MohamedShawky closed 7 years ago

MohamedShawky commented 7 years ago

@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", }

]

}

angvp commented 7 years ago

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.