def serialize_queryset(self, queryset):
object_data = []<EOL>is_queryset = False<EOL>query_fields = self.get_fields()<EOL>try:<EOL><INDENT>iter(queryset)<EOL>is_queryset = True<EOL>raw_data = serializers.serialize(self.serializer_name, queryset, fields=query_fields,<EOL>use_natural_keys=self.serialize_natural_keys)<EOL><DEDENT>except TypeError:  <EOL><INDENT>raw_data = serializers.serialize(self.serializer_name, [queryset, ], fields=query_fields,<EOL>use_natural_keys=self.serialize_natural_keys)<EOL><DEDENT>for obj in raw_data:  <EOL><INDENT>obj['<STR_LIT>']['<STR_LIT>'] = obj['<STR_LIT>']<EOL>object_data.append(obj['<STR_LIT>'])<EOL><DEDENT>if is_queryset:<EOL><INDENT>return object_data<EOL><DEDENT>return object_data[<NUM_LIT:0>]<EOL>
Return serialized queryset or single object as python dictionary
serialize() only works on iterables, so to serialize a single object we put it in a list