title: JsonResponse with model instance including M2M
body: <p>It seems that you cannot replace</p>
  
  <pre><code>from django.core import serializers
  from django.http import HttpResponse, JsonResponse
  
  qs = MyModel.objects.filter(pk=1)
  data = serializers.serialize('json', qs, fields=('id', 'name', 'my_m2m_field'))
  # I want data of the one instance only.
  data = data[data.find('{', 3, 15):data.rfind('}', -60, -3) + 1]
  return HttpResponse(data, content_type='application/json')
  </code></pre>
  
  <p>by <code>JsonResponse</code>, can you? (I don't mean to replace just the last line by <code>return JsonResponse(data)</code> for this doesn't make sense in my opinion.)</p>
  
  <p>For this results in an error:</p>
  
  <pre><code>my_m2m_ids = qs[0].my_m2m_field.all().values_list('id', 'flat=True') # = [3, 2]
  dic = {'my_m2m_ids': my_m2m_ids} # also tried `my_m2m_ids[:]`
  dic.update(qs.values('id', 'name')[0]) # also tried `list(qs.`… and `dict(qs.`…
  return JsonResponse(dic) # also tried `safe=False`
  </code></pre>
  
  <p>Error: <code>TypeError at &lt;path&gt; [3, 2] is not JSON serializable</code>. I don't know exactly why but I think it's caused somehow by the <code>ValuesQuerySet</code> retruned by <code>values()</code> or by the <code>ValuesListQuerySet</code> returnd by <code>values_list()</code>.</p>
  
  <p>Is there any better/shorter solution? For I think it's both not ideal.</p>
  
  <h2>Update</h2>
  
  <p>It works after converting the <code>ValuesListQuerySet</code> to a <code>list</code> (by <code>my_m2m_ids = list(my_m2m_ids)</code>, but <code>my_m2m_ids[:]</code> obviously doesn't work).</p>
  
  <p>But I still loved to be able to use <code>JsonResponse</code> like this: 
  <code>return JsonResponse(MyModel.objects.get(pk=1).only('id', 'name', 'my_m2m_field))</code> (or similar).</p>