'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'

def serialize_queryset(self, queryset):

    object_data = []
    is_queryset = False
    query_fields = self.get_fields()
    try:
        iter(queryset)
        is_queryset = True
        raw_data = serializers.serialize(self.serializer_name, queryset, fields=query_fields, use_natural_keys=self.serialize_natural_keys)
    except TypeError:
        raw_data = serializers.serialize(self.serializer_name, [queryset], fields=query_fields, use_natural_keys=self.serialize_natural_keys)
    for obj in raw_data:
        obj['fields']['pk'] = obj['pk']
        object_data.append(obj['fields'])
    if is_queryset:
        return object_data
    return object_data[0]
