[Django]-ListSerializer in Django Restful – When is it called?

3πŸ‘

βœ…

Per the docs:

The ListSerializer class provides the behavior for serializing and
validating multiple objects at once. You won’t typically need to use
ListSerializer directly, but should instead simply pass many=True when
instantiating a serializer

You can add many=True to your serializer

class FileSerializer(serializers.ModelSerializer):

def __init__(self, *args, **kwargs):
    kwargs['many'] = kwargs.get('many', True)
    super().__init__(*args, **kwargs)

Potential dupe of How do I create multiple model instances with Django Rest Framework?

πŸ‘€Sam Sunde

Leave a comment