title: How can I JSON serialize a queryset on Django?
body: <p>I'd like to return on my ajax response a queryset, this is the error I get when I try to serialize a queryset.</p>
  
  <blockquote>
    <p>TypeError: 'Font: FontName' is not JSON serializable</p>
  </blockquote>
  
  <p>I am using JSON response like so : </p>
  
  <pre><code>...
  return JsonResponse({
      'foo': Font.objects.filter(id=1).first(),
  })
  </code></pre>
  
  <hr>
  
  <p>I also tried, same error : </p>
  
  <pre><code>response = json.dumps({
      'foo' : tmp_fonts,
  })
  
  return HttpResponse(response, content_type='application/json')
  </code></pre>
  
  <hr>
  
  <p><strong>third try :</strong> </p>
  
  <blockquote>
    <p>AttributeError: 'str' object has no attribute '_meta' </p>
  </blockquote>
  
  <pre><code># tmp_fonts = [&lt;Font:CaviarDream&gt;, &lt;Font:Arial&gt;, &lt;Font:Calibri&gt;, etc...]
  
  return JsonResponse({
      'foo': serializers.serialize('json', tmp_fonts),
  })
  </code></pre>
  
  <p>I'd like to be able to get it back on response and display every fields in the query on my template. Is this even possible ? </p>
  
  <hr>
  
  <p><strong>Model :</strong> </p>
  
  <pre><code>class UserInfo(models.Model):
      organisation = models.CharField(max_length=255)
      font = models.ManyToManyField(Font)
  
  class Font(models.Model):
      name = models.CharField(max_length=255)
  </code></pre>