title: Django rest fetch data from bridge model
body: <p>I want to get all the user details and list of all the roles against the 
  user details model
  My Models</p>
  
  <pre class="lang-py prettyprint-override"><code>class UserDetail(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE,
                                  related_name='userdetail_user', default='111')
      cn = models.CharField(max_length=200)
      sn = models.CharField(max_length=200)
      u_id = models.CharField(max_length=200)
      display_name_cn = models.CharField(max_length=200)
      display_name_en = models.CharField(max_length=200)
      given_name = models.CharField(max_length=200)
      employee_number = models.CharField(max_length=200)
      email = models.CharField(max_length=200)
      created_at = models.DateTimeField(default=datetime.now, blank=True)
      last_login = models.DateTimeField(default=datetime.now, blank=True)
  
      def __str__(self):
          return self.given_name
  
  
  class Role(models.Model):
      title = models.CharField(max_length=20)
      description = models.CharField(max_length=200)
      created_at = models.DateTimeField(default=datetime.now, blank=True)
      last_updated = models.DateTimeField(default=datetime.now, blank=True)
      status = models.BooleanField(default=True)
  
      def __str__(self):
          return self.title
  
  
  class UserRole(models.Model):
      userdetail = models.ForeignKey(UserDetail, on_delete=models.CASCADE,
                                     related_name='userrole_userdetail')
      role = models.ForeignKey(Role, on_delete=models.CASCADE)
      approver = models.ForeignKey(UserDetail, on_delete=models.SET_NULL,
                                   null=True,
                                   related_name='userrole_userdetail_approver')
      created_at = models.DateTimeField(default=datetime.now, blank=True)
      last_updated = models.DateTimeField(default=datetime.now, blank=True)
      status = models.BooleanField(default=True)
  
  </code></pre>
  
  <p>My Serializers</p>
  
  <pre class="lang-py prettyprint-override"><code>class UserSerializer(serializers.ModelSerializer):
      class Meta:
          model = User
          fields = ('id', 'username', 'email')
  
  
  class UserRoleSerializer(serializers.ModelSerializer):
      class Meta:
          model = UserRole
          fields = (
              'id', 'userdetail', 'role', 'approver', 'last_updated', 'status')
          depth = 1
  
      def to_representation(self, instance):
          representation = super(UserRoleSerializer, self).to_representation(
              instance)
          representation['userdetail'] = UserDetailSerializer(
              instance.userdetail).data
          representation['role'] = RoleSerializer(instance.role).data
          representation['approver'] = UserDetailSerializer(
              instance.approver).data
          return representation
  
  
  class RoleSerializer(serializers.ModelSerializer):
      class Meta:
          model = Role
          fields = ('id', 'title', 'description', 'last_updated', 'status')
  
  
  class UserDetailSerializer(serializers.ModelSerializer):
      user = UserSerializer()
      roles = serializers.SerializerMethodField(read_only=True)
  
      class Meta:
          model = UserDetail
          fields = ('id', 'roles', 'user', 'cn', 'sn', 'u_id', 'display_name_cn',
                    'display_name_en', 'given_name', 'employee_number', 'email',
                    'last_login')
  
          lookup_field = 'u_id'
  
      def get_roles(self, obj):
  
          roles = UserRole.objects.filter(userdetail=obj)
          return roles
  </code></pre>
  
  <p>When I try to fetch all the user details it gives me an error 
  "Object of type 'UserRole' is not JSON serializable".</p>
  
  <p>I have already tried to serialize the list of object fetched inside get_roles method of UserDetailsSerializer but its no help</p>