title: How do I test the foreign key object on Django model
body: <p>I want to pass foreign key object(Category) on the model(Article) when testing.Currently, I create the category object and then i pass its variable to my article test data.I am currently gettting this error <code>TypeError: Object of type 'Category' is not JSON serializable.</code> My goal is to be able to create a category and then pass it into the article test data when testing creation of a new article.Any ideas into how i can implement this properly ?</p>
  
  <p>base_test.py</p>
  
  <pre><code>class BaseTest:
      """
      Class contains data to be used for testing
      """
  
      def __init__(self):
  
          self.title = "How to tnnrain your flywwwwwwwwwwf"
          self.description = "Ever wondner how toddddd ddddwwwwd?"
          self.body = "You have to benlieve becausedddddddddcf"
  
          self.category = Category.objects.create(
              title='test category',
          )
          self.category.save()
  
  
  
  
         """ sample article data """
         self.create_article = {
              "article": {
                  "title": self.title,
                  "description": self.description,
                  "body": self.body,
                  "tags": ["reactjs"],
                  "category": self.category
  
  
              }
          }
  </code></pre>
  
  <p>test_article.py</p>
  
  <pre><code>from rest_framework.test import APIClient, APITestCase
  from rest_framework import status
  from ..test_authentication.test_base import BaseTest
  from authors.apps.articles.models import Article, Category
  from authors.apps.authentication.models import User
  
  class ArticlesTest(APITestCase,BaseTest):
      def setUp(self):
          BaseTest.__init__(self)
          self.client = APIClient()
  
      """ method for testing creation of a new article """
      def test_create_article(self):
          self.create_login_user()
          response = self.client.post('/api/articles/',self.create_article, 
          format="json")
          self.assertEqual(response.status_code, status.HTTP_201_CREATED)
  </code></pre>
  
  <p>Models.py</p>
  
  <pre><code>class Category(models.Model):
        title = models.CharField(max_length=100)
  
        class Meta: 
              verbose_name_plural = "Categories"
  
        def __str__(self):
              return self.title
  
  class Article(models.Model):
  
        title = models.CharField(max_length=255, null=False, blank=False)
  
        slug = models.SlugField(max_length=100, unique=True)
  
        description = models.TextField(null=False, blank=False)
  
        body = models.TextField(null=False, blank=False,)    
  
        category = models.ForeignKey(Category, 
                           on_delete=models.CASCADE)
  </code></pre>