ModelSerializer with data as list
<p>I have a ModelSerializer class as follows which I want to accept a list of items or a single item (dictionary) as data. The documentation states that passing "many" as True will support my requirement.</p>

<pre><code>class PointSerializer(serializers.ModelSerializer):
    class Meta:
        model = Point

     def __init__(self, *args, **kwargs):
         if "data" in kwargs:
             if isinstance(kwargs["data"]):
                 kwargs["many"] = True
         super(PointSerializer, self).__init__(*args, **kwargs)
</code></pre>

<p>Now, providing data dictionary as follows works:</p>

<pre><code>p = PointSerializer(data={'x':10, 'y': 12})
p.is_valid() # True
</code></pre>

<p>But this, with a list of dictionaries, fails:</p>

<pre><code>p = PointSerializer(data=[{'x':10, 'y':12}, {'x':12, 'y':12}])
p.is_valid() # False
p.errors() # {'non_field_errors': ['Invalid data. Expected a dictionary, but got a list.']}
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>Thanks to the chosen answer, I've changed my code to the following and it works fine:</p>

<pre><code>class PointSerializer(serializers.ModelSerializer):

    class Meta:
        model = Point

&gt;&gt;&gt; ps = PointSerializer(data={'x':10, 'y':12})
&gt;&gt;&gt; ps.is_valid()
... True
&gt;&gt;&gt; ps = PointSerializer(data=[{'x':10, 'y':12}, {'x':12, 'y':12}], many=True)
&gt;&gt;&gt; ps.is_valid()
... True
</code></pre>