Deleting database objectsΒΆ

This section is a topic guide about how to customize behaviour around deleting records.

Unlike Django, Lino has PROTECT as the default on_delete strategy in ForeignKey fields. If you want CASCADE, then you specify it explicitly using the allow_cascaded_delete attribute on the model whose instances will be deleted.

The disable_delete method of a model decides whether a given database object may be deleted or not. Also the disable_delete method of an actor.

The disable_delete item in data_record is a "preview" of whether that row can be deleted or not. The front end may use this information to disable or enable its delete button.

But the DeleteSelected action will verify again before actually deleting a row.

When Lino analyzes the application's models at startup, it adds a "disable_delete handler" (lino.core.ddh) to every model.

The lino.utils.diag.Analyzer.show_foreign_keys() can help to find examples for writing tests. It is used in specs like Deletion handlers in Lino Noi or Database structure in Lino Voga.