from rest_framework import serializers


from models import Page


class PageSerializer(serializers.ModelSerializer):
    parent = serializers.PrimaryKeyRelatedField(required=False)
    children = serializers.PrimaryKeyRelatedField(many=True, required=False)

    class Meta:
        model = Page
        fields = (
            'id',
            'parent',
            'children',
            'title',
            'slug',
            'url',
            'content',
            'summary',
            'author',
            'status',
            'publish_date',
            'type',
            'created',
            'modified'
        )


from rest_framework import serializers


from models import Page


class PageSerializer(serializers.ModelSerializer):
    parent = serializers.PrimaryKeyRelatedField(required=False)
    children = serializers.PrimaryKeyRelatedField(many=True, required=False, read_only=True)

    class Meta:
        model = Page
        fields = (
            'id',
            'parent',
            'children',
            'title',
            'slug',
            'url',
            'content',
            'summary',
            'author',
            'status',
            'publish_date',
            'type',
            'created',
            'modified'
        )


Make the children field in the api read only.
Make the children field in the api read only.

  from rest_framework import serializers
  
  
  from models import Page
  
  
  class PageSerializer(serializers.ModelSerializer):
      parent = serializers.PrimaryKeyRelatedField(required=False)
-     children = serializers.PrimaryKeyRelatedField(many=True, required=False)
+     children = serializers.PrimaryKeyRelatedField(many=True, required=False, read_only=True)
  
      class Meta:
          model = Page
          fields = (
              'id',
              'parent',
              'children',
              'title',
              'slug',
              'url',
              'content',
              'summary',
              'author',
              'status',
              'publish_date',
              'type',
              'created',
              'modified'
          )
  
  
Make the children field in the api read only.
## Code Before:
from rest_framework import serializers


from models import Page


class PageSerializer(serializers.ModelSerializer):
    parent = serializers.PrimaryKeyRelatedField(required=False)
    children = serializers.PrimaryKeyRelatedField(many=True, required=False)

    class Meta:
        model = Page
        fields = (
            'id',
            'parent',
            'children',
            'title',
            'slug',
            'url',
            'content',
            'summary',
            'author',
            'status',
            'publish_date',
            'type',
            'created',
            'modified'
        )


## Instruction:
Make the children field in the api read only.
## Code After:
from rest_framework import serializers


from models import Page


class PageSerializer(serializers.ModelSerializer):
    parent = serializers.PrimaryKeyRelatedField(required=False)
    children = serializers.PrimaryKeyRelatedField(many=True, required=False, read_only=True)

    class Meta:
        model = Page
        fields = (
            'id',
            'parent',
            'children',
            'title',
            'slug',
            'url',
            'content',
            'summary',
            'author',
            'status',
            'publish_date',
            'type',
            'created',
            'modified'
        )

