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 07:48:37 +0200 |
| commit | 562e3bc09aa094a2ebbd3890fa233d04daafa8c9 (patch) | |
| tree | 30829fa2790e23d0e4b0c01d3742a90bfdb3df06 /docs/ref | |
| parent | 87da2833384b7acd99a778a78e07ea6640f54f35 (diff) | |
Refs #23435 -- Added note about GenericForeignKey indexes to docs.
Diffstat (limited to 'docs/ref')
| -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 c23f538b38..d115d434ac 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 |
