code: def to_representation(self, obj):
          
          representation = {}
  
          for name, field in self.fields.items():
              if field.write_only:
                  continue
  
              # note fields do not know their names in source representation
              # but may know what attribute they target from source object
              attribute = self.get_attribute(obj, field.source or name)
  
              if attribute is None:
                  # Skip none attributes so fields do not have to deal with them
                  representation[name] = [] if field.many else None
              elif field.many:
                  representation[name] = [
                      field.to_representation(item) for item in attribute
                  ]
              else:
                  representation[name] = field.to_representation(attribute)
  
          return representation
docs: Convert given internal object instance into representation dict.
  
          Representation dict may be later serialized to the content-type
          of choice in the resource HTTP method handler.
  
          This loops over all fields and retrieves source keys/attributes as
          field values with respect to optional field sources and converts each
          one using ``field.to_representation()`` method.
  
          Args:
              obj (object): internal object that needs to be represented
  
          Returns:
              dict: representation dictionary