def _get_filtered_query(
    sender: Type[Model], instance: Model, to_class: Type[Model]
) -> QuerySet:
    """
    Helper function.
    Gets the query filtered by the appropriate class name.
    """
    pk = getattr(instance, f"{to_class.get_name()}").pk
    filter_kwargs = {f"{to_class.get_name()}": pk}
    query = sender.objects.filter(**filter_kwargs)
    return query

    Helper function.
    Gets the query filtered by the appropriate class name.
    
tests/test_ordering/test_default_through_relation_order.py