Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

lino.core.ddh

Defines the DisableDeleteHandler class.

See Customize delete behaviour.

Functions

traverse_ddh_fklist(model[, ignore_mti_parents])

Return an iterator over each foreign key (in other models) that points to this model.

Classes

DisableDeleteHandler(model)

A helper object used to find out whether a known object can be deleted or not.

class lino.core.ddh.DisableDeleteHandler(model)

Bases: object

A helper object used to find out whether a known object can be deleted or not.

Lino installs an instance of this on each model in an attribute _lino_ddh during kernel startup.

fklist

A list of tuples (model, fk), one item for each FK field in the application which points to this model.

model

The owning model (i.e. m._lino_ddh.model is m is True for every model)

disable_delete_on_object(obj, ignore_models={})

Return a veto message that explains why this object cannot be deleted. Return None if there is no veto.

If ignore_model (a set of model class objects) is specified, do not check for vetos on ForeignKey fields defined on one of these models.

lino.core.ddh.traverse_ddh_fklist(model, ignore_mti_parents=True)

Return an iterator over each foreign key (in other models) that points to this model. Used e.g. to predict the related objects that are going to be deleted in cascade when a database object is being deleted.

When an application uses MTI (e.g. with a Participant model being a specialization of Person, which itself a specialization of Partner) and we merge two Participants, then we must of course also merge their invoices and bank statement items (linked via a FK to Partner) and their contact roles (linked via a FK to Person).

See also #3891 (Lino says there are 2 related adresses when there is only one).