Refs #23435 -- Added note about GenericForeignKey indexes to docs.

This commit is contained in:
Steven DeMartini 2022-04-28 12:15:40 -07:00 committed by Mariusz Felisiak
parent 87da283338
commit 562e3bc09a
1 changed files with 13 additions and 0 deletions

View File

@ -255,6 +255,11 @@ For example, it could be used for a tagging system like so::
def __str__(self): def __str__(self):
return self.tag return self.tag
class Meta:
indexes = [
models.Index(fields=["content_type", "object_id"]),
]
A normal :class:`~django.db.models.ForeignKey` can only "point A normal :class:`~django.db.models.ForeignKey` can only "point
to" one other model, which means that if the ``TaggedItem`` model used a to" one other model, which means that if the ``TaggedItem`` model used a
:class:`~django.db.models.ForeignKey` it would have to :class:`~django.db.models.ForeignKey` it would have to
@ -285,6 +290,14 @@ model:
:class:`~django.contrib.contenttypes.fields.GenericForeignKey` will :class:`~django.contrib.contenttypes.fields.GenericForeignKey` will
look for. 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 .. attribute:: GenericForeignKey.for_concrete_model
If ``False``, the field will be able to reference proxy models. Default If ``False``, the field will be able to reference proxy models. Default