Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
GenericForeignKey fields¶
The GenericForeignKey field (GFK) is a great feature provided by Django’s django.contrib.contenttypes module. While a normal ForeignKey field can point to a database object of a given model, a GenericForeignKey can point to a database object of any model.
This section provides a topic overview. See also
A tested example of GFK fields and
test_broken_gfks
).
Lino’s disable_delete
method tests for related objects, which automatically includes also
those which are related using a GFK. non-nullable and warning before
message.
In order to use GFKs, you must have django.contrib.contenttypes
in
your INSTALLED_APPS
. In a Lino application we recommend to
use lino.modlib.contenttypes
, which is a thin wrapper around
Django’s original app. Lino’s version gives you additional
functionality:
the
Controllable
model mixinthe
BrokenGFKs
table
In Lino you can configure the cascading behaviour from the model
which defines the GFK, either by using the
allow_cascaded_delete
attribute or by
defining a nullable GFK.