def METHOD_NAME(self, instance, fields, api=False):
    """
    Returns a dictionary representation of an instance.
    """
    # Prepare the instance and call Django's model_to_dict() to extract all fields
    model_dict = METHOD_NAME(self.prepare_instance(instance), fields=fields)
    # Map any additional (non-field) instance attributes that were specified
    for attr in fields:
        if hasattr(instance, attr) and attr not in model_dict:
            model_dict[attr] = getattr(instance, attr)
    for key, value in list(model_dict.items()):
        try:
            field = instance._meta.get_field(key)
        except FieldDoesNotExist:
            # Attribute is not a model field
            continue
        # Handle ManyToManyFields
        if value and type(field) in (ManyToManyField, TaggableManager) and api:
            if field.related_model is ContentType:
                model_dict[key] = sorted(
                    [content_type_identifier(ct) for ct in value]
                )
            else:
                model_dict[key] = sorted([obj.pk for obj in value])
        elif api:
            # Replace ContentType numeric IDs with <app_label>.<model>
            if type(getattr(instance, key)) is ContentType:
                ct = ContentType.objects.get(pk=value)
                model_dict[key] = content_type_identifier(ct)
            # Handle IP related fields
            elif type(value) in (
                IPv4Address,
                IPv6Address,
                IPv4Interface,
                IPv6Interface,
            ):
                model_dict[key] = str(value)
    return model_dict