Hi All,
I need a help about rest_framework because I can't figure out the problem.
need to insert bulk json object via django rest_framework however, I get an error message when send data to django rest page ;
[
{"name":"m1","duration":120,"rating":4.7},
{"name":"m2","duration":120,"rating":4.5}
]
typed following line ;
{ "non_field_errors": [ "Invalid data. Expected a dictionary, but got list." ] }my serializer.py file include following code block;
class DrfSerializerV2(serializers.ModelSerializer): def __init__(self,*args,**kwargs):many=kwargs.pop('many',True)super(DrfSerializerV2,self).__init__(many=True,*args,**kwargs) class Meta: model = DrfData fields=['id','name','duration','rating','typ']and my views.py file ;
class ActionViewSet(viewsets.ModelViewSet): queryset = DrfData.objects.filter(typ="action") serializer_class = serializers.DrfSerializerV2finally send json file via post;
[ {"name":"m1","duration":120,"rating":4.7}, {"name":"m2","duration":120,"rating":4.5} ]and django typed following error message;
{ "non_field_errors": [ "Invalid data. Expected a dictionary, but got list." ] }
however, I can't handle this error message. if I send sperataly, there is no problem.
but, I can't resolve this error for multiple json insert
Thanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/182af5ab-a3de-4abe-83e4-ff0e2571f98an%40googlegroups.com.


No comments:
Post a Comment