title: How to create a Parent/Child relationship with Django REST models?
body: <p>I am new to Django REST and want to basically create a
  <a href="https://i.stack.imgur.com/sVRlR.png" rel="nofollow noreferrer">join table like this</a>.</p>
  <p>One Page (txt doc) can have a parent and child Page. Each and every Page can be a parent and child of multiple other pages.</p>
  <p>Both the Page Entity and PageToPage Entity have an implemented model &amp; serializer in the backend, where the <code>serializers.py</code> look like this:</p>
  <pre><code>class PageSerializer(serializers.ModelSerializer):
      class Meta:
          model = Page
          fields = ['pkid', 'title', 'text', 'creation_date', 'page_of_user']
  
  class PageToPageSerializer(serializers.ModelSerializer): 
        parent_page = PageSerializer(many=True, read_only=True)
        child_page = PageSerializer(many=True, read_only=True)
        class Meta:
            model = PageToPage
            fields = ['pkid', 'parent_page', 'child_page']
  </code></pre>
  <p>and <code>models.py</code> :</p>
  <pre><code>class Page(models.Model):
      pkid = models.BigAutoField(primary_key=True, editable=False)
      page_of_user = models.ForeignKey(User, related_name='pages', on_delete=models.CASCADE)
      title = models.TextField(blank=True, default='')
      text = models.TextField(blank=True, default='')
      creation_date = models.DateField(auto_now_add=True)
  
  class PageToPage(models.Model):
      pkid = models.BigAutoField(primary_key=True, editable=False)
      parent_page = models.ForeignKey(Page, related_name='parent_page', on_delete=models.CASCADE, blank=True, null=True)
      child_page = models.ForeignKey(Page, related_name='child_page', on_delete=models.CASCADE, blank=True, null=True)
  </code></pre>
  <p>When entering the manage.py shell and creating a PageToPage object, it just yields empty results:</p>
  <pre><code># Create Pages
  p1 = Page(title=&quot;Parent Page 1&quot;, text=&quot;Once upon a time, there was a young man...&quot;, page_of_user=u2)
  p1.save()
  p3 = Page(title=&quot;Child Page 1&quot;, text=&quot;Once upon a time, there was a young man...&quot;, page_of_user=u2)
  p3.save()
  
  # Create Page Relationships
  ptp = PageToPage(parent_page=p1, child_page=p3)
  ptp.save()
  
  # Select all Pages
  print(&quot;Created Pages:&quot;)
  ser2 = PageSerializer(Page.objects.all(), many=True)
  print(ser2.data)
  
  # Select all Page to Page relationships
  ser_ptp = PageToPageSerializer(PageToPage.objects.all())
  print(&quot;Created Page relationships:&quot;)
  print(ser_ptp.data)
  </code></pre>
  <p>Output:</p>
  <pre><code>&gt;&gt;&gt; Created Pages:
  &gt;&gt;&gt; [OrderedDict([('pkid', 1), ('title', 'Test Page number 1'), ('text', 'Just some sample text'), ('creation_date', '17.06.2021'), ('page_of_user', UUID('eeec0437-75f2-44ba-935d-96fcb78e38c6'))]), ...]
  &gt;&gt;&gt; Created Page relationships:
  &gt;&gt;&gt; {}
  </code></pre>
  <p>What am I doing wrong? Any help is really appreciated!</p>