def make_raw(query, exclude=None):
 rows = []
 for instance in query:
  data = model_to_dict(instance, exclude=exclude)
  '\n        In Django 1.10, model_to_dict resolves ManyToManyField as a QuerySet.\n        Previously, we used to get primary keys. Following code converts the\n        QuerySet into primary keys.\n        For reference: https://www.mail-archive.com/django-updates@googlegroups.com/msg163020.html\n        '
  for field in instance._meta.many_to_many:
   value = data[field.name]
   if isinstance(value, QuerySet):
    data[field.name] = [row.pk for row in value]
  rows.append(data)
 return rows

def make_raw ( query , exclude = None ) : rows = [ ] for instance in query : data = model_to_dict ( instance , exclude = exclude ) for field in instance . _meta . many_to_many : value = data [ field . name ] if isinstance ( value , QuerySet ) : data [ field . name ] = [ row . pk for row in value ] rows . append ( data ) return rows
takes a django query and returns a jsonable list of dictionaries corresponding to the database rows .