mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #36485 -- Removed unnecessary parentheses in :meth: and :func: roles in docs.
This commit is contained in:
@@ -966,7 +966,7 @@ See :ref:`ref-models-update-fields` for more details.
|
||||
|
||||
.. admonition:: Overridden model methods are not called on bulk operations
|
||||
|
||||
Note that the :meth:`~Model.delete()` method for an object is not
|
||||
Note that the :meth:`~Model.delete` method for an object is not
|
||||
necessarily called when :ref:`deleting objects in bulk using a
|
||||
QuerySet <topics-db-queries-delete>` or as a result of a :attr:`cascading
|
||||
delete <django.db.models.ForeignKey.on_delete>`. To ensure customized
|
||||
@@ -977,7 +977,7 @@ See :ref:`ref-models-update-fields` for more details.
|
||||
Unfortunately, there isn't a workaround when
|
||||
:meth:`creating<django.db.models.query.QuerySet.bulk_create>` or
|
||||
:meth:`updating<django.db.models.query.QuerySet.update>` objects in bulk,
|
||||
since none of :meth:`~Model.save()`,
|
||||
since none of :meth:`~Model.save`,
|
||||
:data:`~django.db.models.signals.pre_save`, and
|
||||
:data:`~django.db.models.signals.post_save` are called.
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ Use standard DB optimization techniques
|
||||
:attr:`Meta.indexes <django.db.models.Options.indexes>` or
|
||||
:attr:`Field.db_index <django.db.models.Field.db_index>` to add these from
|
||||
Django. Consider adding indexes to fields that you frequently query using
|
||||
:meth:`~django.db.models.query.QuerySet.filter()`,
|
||||
:meth:`~django.db.models.query.QuerySet.exclude()`,
|
||||
:meth:`~django.db.models.query.QuerySet.order_by()`, etc. as indexes may help
|
||||
:meth:`~django.db.models.query.QuerySet.filter`,
|
||||
:meth:`~django.db.models.query.QuerySet.exclude`,
|
||||
:meth:`~django.db.models.query.QuerySet.order_by`, etc. as indexes may help
|
||||
to speed up lookups. Note that determining the best indexes is a complex
|
||||
database-dependent topic that will depend on your particular application.
|
||||
The overhead of maintaining an index may outweigh any gains in query speed.
|
||||
@@ -115,7 +115,7 @@ Use ``iterator()``
|
||||
|
||||
When you have a lot of objects, the caching behavior of the ``QuerySet`` can
|
||||
cause a large amount of memory to be used. In this case,
|
||||
:meth:`~django.db.models.query.QuerySet.iterator()` may help.
|
||||
:meth:`~django.db.models.query.QuerySet.iterator` may help.
|
||||
|
||||
Use ``explain()``
|
||||
-----------------
|
||||
@@ -227,7 +227,7 @@ Use ``QuerySet.values()`` and ``values_list()``
|
||||
|
||||
When you only want a ``dict`` or ``list`` of values, and don't need ORM model
|
||||
objects, make appropriate usage of
|
||||
:meth:`~django.db.models.query.QuerySet.values()`.
|
||||
:meth:`~django.db.models.query.QuerySet.values`.
|
||||
These can be useful for replacing model objects in template code - as long as
|
||||
the dicts you supply have the same attributes as those used in the template,
|
||||
you are fine.
|
||||
@@ -235,8 +235,8 @@ you are fine.
|
||||
Use ``QuerySet.defer()`` and ``only()``
|
||||
---------------------------------------
|
||||
|
||||
Use :meth:`~django.db.models.query.QuerySet.defer()` and
|
||||
:meth:`~django.db.models.query.QuerySet.only()` if there are database columns
|
||||
Use :meth:`~django.db.models.query.QuerySet.defer` and
|
||||
:meth:`~django.db.models.query.QuerySet.only` if there are database columns
|
||||
you know that you won't need (or won't need in most cases) to avoid loading
|
||||
them. Note that if you *do* use them, the ORM will have to go and get them in
|
||||
a separate query, making this a pessimization if you use it inappropriately.
|
||||
@@ -349,7 +349,7 @@ Ordering is not free; each field to order by is an operation the database must
|
||||
perform. If a model has a default ordering (:attr:`Meta.ordering
|
||||
<django.db.models.Options.ordering>`) and you don't need it, remove
|
||||
it on a ``QuerySet`` by calling
|
||||
:meth:`~django.db.models.query.QuerySet.order_by()` with no parameters.
|
||||
:meth:`~django.db.models.query.QuerySet.order_by` with no parameters.
|
||||
|
||||
Adding an index to your database may help to improve ordering performance.
|
||||
|
||||
@@ -362,7 +362,7 @@ Create in bulk
|
||||
--------------
|
||||
|
||||
When creating objects, where possible, use the
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_create()` method to reduce the
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_create` method to reduce the
|
||||
number of SQL queries. For example::
|
||||
|
||||
Entry.objects.bulk_create(
|
||||
@@ -385,7 +385,7 @@ Update in bulk
|
||||
--------------
|
||||
|
||||
When updating objects, where possible, use the
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_update()` method to reduce the
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_update` method to reduce the
|
||||
number of SQL queries. Given a list or queryset of objects::
|
||||
|
||||
entries = Entry.objects.bulk_create(
|
||||
@@ -432,7 +432,7 @@ objects to reduce the number of SQL queries. For example::
|
||||
When inserting different pairs of objects into
|
||||
:class:`~django.db.models.ManyToManyField` or when the custom
|
||||
:attr:`~django.db.models.ManyToManyField.through` table is defined, use
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_create()` method to reduce the
|
||||
:meth:`~django.db.models.query.QuerySet.bulk_create` method to reduce the
|
||||
number of SQL queries. For example::
|
||||
|
||||
PizzaToppingRelationship = Pizza.toppings.through
|
||||
|
||||
@@ -83,7 +83,7 @@ The :meth:`~django.db.models.Model.save` method has no return value.
|
||||
:meth:`~django.db.models.Model.save` for complete details.
|
||||
|
||||
To create and save an object in a single step, use the
|
||||
:meth:`~django.db.models.query.QuerySet.create()` method.
|
||||
:meth:`~django.db.models.query.QuerySet.create` method.
|
||||
|
||||
Saving changes to objects
|
||||
=========================
|
||||
|
||||
@@ -5,7 +5,7 @@ Performing raw SQL queries
|
||||
.. currentmodule:: django.db.models
|
||||
|
||||
Django gives you two ways of performing raw SQL queries: you can use
|
||||
:meth:`Manager.raw()` to `perform raw queries and return model instances`__, or
|
||||
:meth:`Manager.raw` to `perform raw queries and return model instances`__, or
|
||||
you can avoid the model layer entirely and `execute custom SQL directly`__.
|
||||
|
||||
__ `performing raw queries`_
|
||||
@@ -170,7 +170,7 @@ Fields may also be left out:
|
||||
>>> people = Person.objects.raw("SELECT id, first_name FROM myapp_person")
|
||||
|
||||
The ``Person`` objects returned by this query will be deferred model instances
|
||||
(see :meth:`~django.db.models.query.QuerySet.defer()`). This means that the
|
||||
(see :meth:`~django.db.models.query.QuerySet.defer`). This means that the
|
||||
fields that are omitted from the query will be loaded on demand. For example:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
Reference in New Issue
Block a user