from rest_framework import serializers
from .models import Challenge, Role

from core.serializers import UserSerializer


class RoleSerializer(serializers.ModelSerializer):
    #user = serializers.RelatedField(many=True)
    #user = serializers.PrimaryKeyRelatedField()
    #user = serializers.HyperlinkedRelatedField()
    user = UserSerializer()
    #challenge = ChallengeSerializer()
    challenge = serializers.RelatedField()

    class Meta:
        model = Role
        fields = ("id", "user", "type", "challenge")


class ChallengeSerializer(serializers.ModelSerializer):
    #role_set = serializers.HyperlinkedRelatedField(view_name="role_api_retrieve", many=True)
    #role_set = serializers.RelatedField(many=True)
    #role_set = serializers.SlugRelatedField(many=True, slug_field="type")
    role_set = RoleSerializer(many=True)

    class Meta:
        model = Challenge
        fields = ("id", "title", "body", "repo_name", "creation_datetime",
                  "role_set")

from rest_framework import serializers
from .models import Challenge, Role

from core.serializers import UserSerializer
from comments.serializers import CommentSerializer


class RoleSerializer(serializers.ModelSerializer):
    #user = UserSerializer()
    #challenge = serializers.RelatedField()
    comment_set = CommentSerializer()

    class Meta:
        model = Role
        fields = ("id", "user", "type", "challenge", "comment_set")


class ChallengeSerializer(serializers.ModelSerializer):
    #role_set = serializers.HyperlinkedRelatedField(view_name="role_api_retrieve", many=True)
    #role_set = serializers.RelatedField(many=True)
    #role_set = serializers.SlugRelatedField(many=True, slug_field="type")
    role_set = RoleSerializer(many=True)

    class Meta:
        model = Challenge
        fields = ("id", "title", "body", "repo_name", "creation_datetime",
                  "role_set")

Include comments in Role serializer
Include comments in Role serializer

  from rest_framework import serializers
  from .models import Challenge, Role
  
  from core.serializers import UserSerializer
+ from comments.serializers import CommentSerializer
  
  
  class RoleSerializer(serializers.ModelSerializer):
-     #user = serializers.RelatedField(many=True)
-     #user = serializers.PrimaryKeyRelatedField()
-     #user = serializers.HyperlinkedRelatedField()
-     user = UserSerializer()
+     #user = UserSerializer()
-     #challenge = ChallengeSerializer()
-     challenge = serializers.RelatedField()
+     #challenge = serializers.RelatedField()
+     comment_set = CommentSerializer()
  
      class Meta:
          model = Role
-         fields = ("id", "user", "type", "challenge")
+         fields = ("id", "user", "type", "challenge", "comment_set")
  
  
  class ChallengeSerializer(serializers.ModelSerializer):
      #role_set = serializers.HyperlinkedRelatedField(view_name="role_api_retrieve", many=True)
      #role_set = serializers.RelatedField(many=True)
      #role_set = serializers.SlugRelatedField(many=True, slug_field="type")
      role_set = RoleSerializer(many=True)
  
      class Meta:
          model = Challenge
          fields = ("id", "title", "body", "repo_name", "creation_datetime",
                    "role_set")
  
Include comments in Role serializer
## Code Before:
from rest_framework import serializers
from .models import Challenge, Role

from core.serializers import UserSerializer


class RoleSerializer(serializers.ModelSerializer):
    #user = serializers.RelatedField(many=True)
    #user = serializers.PrimaryKeyRelatedField()
    #user = serializers.HyperlinkedRelatedField()
    user = UserSerializer()
    #challenge = ChallengeSerializer()
    challenge = serializers.RelatedField()

    class Meta:
        model = Role
        fields = ("id", "user", "type", "challenge")


class ChallengeSerializer(serializers.ModelSerializer):
    #role_set = serializers.HyperlinkedRelatedField(view_name="role_api_retrieve", many=True)
    #role_set = serializers.RelatedField(many=True)
    #role_set = serializers.SlugRelatedField(many=True, slug_field="type")
    role_set = RoleSerializer(many=True)

    class Meta:
        model = Challenge
        fields = ("id", "title", "body", "repo_name", "creation_datetime",
                  "role_set")

## Instruction:
Include comments in Role serializer
## Code After:
from rest_framework import serializers
from .models import Challenge, Role

from core.serializers import UserSerializer
from comments.serializers import CommentSerializer


class RoleSerializer(serializers.ModelSerializer):
    #user = UserSerializer()
    #challenge = serializers.RelatedField()
    comment_set = CommentSerializer()

    class Meta:
        model = Role
        fields = ("id", "user", "type", "challenge", "comment_set")


class ChallengeSerializer(serializers.ModelSerializer):
    #role_set = serializers.HyperlinkedRelatedField(view_name="role_api_retrieve", many=True)
    #role_set = serializers.RelatedField(many=True)
    #role_set = serializers.SlugRelatedField(many=True, slug_field="type")
    role_set = RoleSerializer(many=True)

    class Meta:
        model = Challenge
        fields = ("id", "title", "body", "repo_name", "creation_datetime",
                  "role_set")
