async def _populate_order_on_insert(
    sender: Type[Model], instance: Model, from_class: Type[Model], to_class: Type[Model]
):
    """
    Helper function.

    Get max values from database for both orders and adds 1 (0 if max is None) if the
    order is not provided. If the order is provided it reorders the existing links
    to match the newly defined order.

    Assumes names f"{model.get_name()}_order" like for Animal: animal_order.
    """
    order_column = f"{from_class.get_name()}_order"
    if getattr(instance, order_column) is None:
        query = _get_filtered_query(sender, instance, to_class)
        max_order = await query.max(order_column)
        max_order = max_order + 1 if max_order is not None else 0
        setattr(instance, order_column, max_order)
    else:
        await _reorder_on_update(
            sender=sender,
            instance=instance,
            from_class=from_class,
            to_class=to_class,
            passed_args={order_column: getattr(instance, order_column)},
        )

    Helper function.

    Get max values from database for both orders and adds 1 (0 if max is None) if the
    order is not provided. If the order is provided it reorders the existing links
    to match the newly defined order.

    Assumes names f"{model.get_name()}_order" like for Animal: animal_order.
    
tests/test_ordering/test_default_through_relation_order.py