title: Django test client does not automatically serialize factories
body: <p>Here's my code:</p>
  
  <pre><code># models.py
  class MyModel(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      name = models.CharField(max_length=10)
      ...
  
  # views.py
  def get_all_models(request):
      return JsonResponse({"models": list(MyModel.objects.all())})
  
  # urls.py
  path('/mypath', views.get_all_models, name='get_all_models'),
  </code></pre>
  
  <p>This code works just fine if I visit <code>/mypath</code>. However, when I run an automated test using Django's test client, I get this error:</p>
  
  <pre><code>*** TypeError: Object of type MyModel is not JSON serializable
  </code></pre>
  
  <p>this is my test:
  from django.test import TestCase, Client
  from blog.tests.factories.user import UserFactory
  from blog.tests.factories.post import PostFactory</p>
  
  <pre><code>class MyModelTest(TestCase):
      def setUp(self):
          self.user = UserFactory.create()
          self.post = MyModelFactory.create(user=self.user)
          self.client = Client()
  
      def test_get_all_models(self):
          response = self.client.get("/mypath")
          pass
  </code></pre>
  
  <p>I suspect it has something to do with my factories:</p>
  
  <pre><code>import factory
  from .models import User, MyModel
  
  class UserFactory(factory.django.DjangoModelFactory):
      class Meta:
          model = User
  
      username = factory.Faker('word')
      email = factory.Faker('email')
  
  class MyModelFactory(factory.django.DjangoModelFactory):
      class Meta:
          model = MyModel
  
      user = factory.SubFactory(UserFactory)
      name = factory.Faker('name')
  </code></pre>
  
  <p>How can I make my factories serializable?</p>
  
  <p><strong>NOTE:</strong>
  This question is not a duplicate. The other questions linked have view handlers that return <code>HttpResponse</code> objects, instead of <code>JsonResponse</code> objects. This distinction is key to my problem, because the error I'm seeing is related to JSON serialization that is supposed to be addressed by the <code>JsonResponse</code> class.</p>
  
  <p>Also, the other questions do not involve factories. Factories are another key component of what I'm trying to do, which is run integration tests against data generated by factories.</p>