def sort_key(item):
    """
    Return the sort value for an item in a collection of included resources.

    Intended for nested, related objects that expose the ``id`` or ``pk`` field.

    :raises: ValueError if the PK cannot be determined.
    """
    if "id" in item:
        return item["id"]
    elif "pk" in item:
        return item["pk"]
    raise ValueError(
        "Item %r does not contain a reference to the 'id'. "
        " Please included it in the serializer." % item
    )