summaryrefslogtreecommitdiff
path: root/docs/ref/models
diff options
context:
space:
mode:
Diffstat (limited to 'docs/ref/models')
-rw-r--r--docs/ref/models/indexes.txt12
-rw-r--r--docs/ref/models/options.txt22
2 files changed, 26 insertions, 8 deletions
diff --git a/docs/ref/models/indexes.txt b/docs/ref/models/indexes.txt
index c3c8d1b6eb..b63e86517c 100644
--- a/docs/ref/models/indexes.txt
+++ b/docs/ref/models/indexes.txt
@@ -8,8 +8,10 @@ Model index reference
.. versionadded:: 1.11
-Index classes ease creating database indexes. This document explains the API
-references of :class:`Index` which includes the `index options`_.
+Index classes ease creating database indexes. They can be added using the
+:attr:`Meta.indexes <django.db.models.Options.indexes>` option. This document
+explains the API references of :class:`Index` which includes the `index
+options`_.
.. admonition:: Referencing built-in indexes
@@ -40,9 +42,3 @@ A list of the name of the fields on which the index is desired.
The name of the index. If ``name`` isn't provided Django will auto-generate a
name. For compatibility with different databases, index names cannot be longer
than 30 characters and shouldn't start with a number (0-9) or underscore (_).
-
-.. seealso::
-
- Use the :class:`~django.db.migrations.operations.AddIndex` and
- :class:`~django.db.migrations.operations.RemoveIndex` operations to add
- and remove indexes.
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt
index 6569c774e8..5d385adf24 100644
--- a/docs/ref/models/options.txt
+++ b/docs/ref/models/options.txt
@@ -390,6 +390,28 @@ Django quotes column and table names behind the scenes.
See :meth:`django.db.models.Model.save()` for more about the old and
new saving algorithm.
+``indexes``
+-----------
+
+.. attribute:: Options.indexes
+
+ .. versionadded:: 1.11
+
+ A list of :doc:`indexes </ref/models/indexes>` that you want to define on
+ the model::
+
+ from django.db import models
+
+ class Customer(models.Model):
+ first_name = models.CharField(max_length=100)
+ last_name = models.CharField(max_length=100)
+
+ class Meta:
+ indexes = [
+ models.Index(fields=['last_name', 'first_name']),
+ models.Index(fields=['first_name'], name='first_name_idx'),
+ ]
+
``unique_together``
-------------------