Related data invalidation

This is the official documentation of the forestadmin-agent-django and forestadmin-agent-flask Python agents.

Your actions may edit records that the user is currently viewing. This is usually not an issue, as after the successful execution of an action, Forest Admin will reload all data that is displayed on the current page.

This is always true, except for a single case: Related Data displayed in custom-built Summary Views ↗. In this case, to avoid displaying stale data, you may want to tell the GUI which data has gone stale.

Example

In the example below, the “Add new transaction” action is accessible from the summary view. This action creates a new transaction and automatically refreshes the “Emitted transactions” Related Data section to see the new transaction.

from typing import Union
from forestadmin.datasource_toolkit.decorators.action.result_builder import ResultBuilder
from forestadmin.datasource_toolkit.decorators.action.context.single import ActionContextSingle
from forestadmin.datasource_toolkit.interfaces.actions import ActionResult

def execute(
    context: ActionContextSingle, result_builder: ResultBuilder
) -> Union[None, ActionResult]:
    # ... Create new transaction here ...

    # Tell the GUI to refresh the "emitted_transactions" related data section.
    # (see left arrow of the screenshot above)
    return result_builder.success(
        "New transaction emitted", {"invalidated": ["emitted_transactions"]}
    )

agent.customize_collection("Company").add_action("Add new transaction", {
    "scope": "Single",
    "execute": execute,
})

Last updated