[Django]-Serializing a list of objects with django-rest-framework

123👍

You can simply add many=True for serialising list.

comments = [Comment(email='leila@example.com', content='foo bar'),
            Comment(email='leila1@example.com', content='foo bar 1'),
            Comment(email='leila2@example.com', content='foo bar 2')]
serializer = CommentSerializer(comments, many=True)
serializer.data

Leave a comment