diff options
| author | Steven DeMartini <sjdemartini@users.noreply.github.com> | 2022-04-28 12:15:40 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-04-29 09:23:01 +0200 |
| commit | 2308fb5806bd30befc9f076905c1fd865e1176bf (patch) | |
| tree | 4704d2da987aab9aafc8e8e89a19e5f65b105f9b | |
| parent | ed6940f0bffc661a36879b8bdba4c7c9ee73cb80 (diff) | |
[4.0.x] Refs #23435 -- Added note about GenericForeignKey indexes to docs.
Backport of 562e3bc09aa094a2ebbd3890fa233d04daafa8c9 from main
| -rw-r--r-- | docs/ref/contrib/contenttypes.txt | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt index 7550f4fc8d..2740afede3 100644 --- a/docs/ref/contrib/contenttypes.txt +++ b/docs/ref/contrib/contenttypes.txt @@ -255,6 +255,11 @@ For example, it could be used for a tagging system like so:: def __str__(self): return self.tag + class Meta: + indexes = [ + models.Index(fields=["content_type", "object_id"]), + ] + A normal :class:`~django.db.models.ForeignKey` can only "point to" one other model, which means that if the ``TaggedItem`` model used a :class:`~django.db.models.ForeignKey` it would have to @@ -285,6 +290,14 @@ model: :class:`~django.contrib.contenttypes.fields.GenericForeignKey` will look for. + Unlike for the :class:`~django.db.models.ForeignKey`, a database index is + *not* automatically created on the + :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, so it's + recommended that you use + :attr:`Meta.indexes <django.db.models.Options.indexes>` to add your own + multiple column index. This behavior :ticket:`may change <23435>` in the + future. + .. attribute:: GenericForeignKey.for_concrete_model If ``False``, the field will be able to reference proxy models. Default |
