37๐
โ
You should be aware of these things,
- Since you are passing a
QuerySet
object, you must not provide thedata
argument. QuerySet
is alist
like object, so you should providemany=True
while serialization.- the
is_valid()
method only is applicable only if you pass a dictionary to thedata
argument, which is not here.
So, change you get_serialized()
method as,
def get_serialized(self, pk, keyword):
queryset = summary.objects.filter(html__pk=pk).filter(keyword=keyword)
serializer = summarySerializer(queryset, many=True)
data = serializer.data
return data["json"]
References
๐คJPG
7๐
As far as I can see you need to provide serializer class with many=True
.
As for docs:
To serialize a queryset or list of objects instead of a single object
instance, you should pass the many=True flag when instantiating the
serializer. You can then pass a queryset or list of objects to be
serialized.
http://www.django-rest-framework.org/api-guide/serializers/#dealing-with-multiple-objects
So the line that raises error should look this way
serializer = summarySerializer(queryset, many=True)
๐คwiaterb
Source:stackexchange.com