diff options
| author | chenesan <pipio1994@gmail.com> | 2016-02-24 15:10:09 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-27 08:48:32 -0500 |
| commit | b84f5ab4ec2d1edbe9a7effa9f75a3caa189bace (patch) | |
| tree | 6e9d4ef21e0e33ea0100b18a5dc0c890391da8e5 /docs | |
| parent | 5fb9756eba01237cc0e550da689b9b79c51c96ed (diff) | |
Fixed #26230 -- Made default_related_name affect related_query_name.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/internals/deprecation.txt | 3 | ||||
| -rw-r--r-- | docs/ref/models/fields.txt | 5 | ||||
| -rw-r--r-- | docs/ref/models/options.txt | 26 | ||||
| -rw-r--r-- | docs/releases/1.10.txt | 28 |
4 files changed, 60 insertions, 2 deletions
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 6e593c787d..81e3600bce 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -138,6 +138,9 @@ details on these changes. * Support for the ``django.core.files.storage.Storage.accessed_time()``, ``created_time()``, and ``modified_time()`` methods will be removed. +* Support for query lookups using the model name when + ``Meta.default_related_name`` is set will be removed. + .. _deprecation-removed-in-1.10: 1.10 diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index de493dda67..6b972660a2 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1333,8 +1333,9 @@ The possible values for :attr:`~ForeignKey.on_delete` are found in .. attribute:: ForeignKey.related_query_name - The name to use for the reverse filter name from the target model. - Defaults to the value of :attr:`related_name` if it is set, otherwise it + The name to use for the reverse filter name from the target model. It + defaults to the value of :attr:`related_name` or + :attr:`~django.db.models.Options.default_related_name` if set, otherwise it defaults to the name of the model:: # Declare the ForeignKey with related_query_name diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index 65fa8acfea..8fbf4b219e 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -103,6 +103,8 @@ Django quotes column and table names behind the scenes. The name that will be used by default for the relation from a related object back to this one. The default is ``<model_name>_set``. + This option also sets :attr:`~ForeignKey.related_query_name`. + As the reverse name for a field should be unique, be careful if you intend to subclass your model. To work around name collisions, part of the name should contain ``'%(app_label)s'`` and ``'%(model_name)s'``, which are @@ -110,6 +112,30 @@ Django quotes column and table names behind the scenes. and the name of the model, both lowercased. See the paragraph on :ref:`related names for abstract models <abstract-related-name>`. + .. deprecated:: 1.10 + + This attribute now affects ``related_query_name``. The old query lookup + name is deprecated:: + + from django.db import models + + class Foo(models.Model): + pass + + class Bar(models.Model): + foo = models.ForeignKey(Foo) + + class Meta: + default_related_name = 'bars' + + :: + + >>> bar = Bar.objects.get(pk=1) + >>> # Using model name "bar" as lookup string is deprecated. + >>> Foo.object.get(bar=bar) + >>> # You should use default_related_name "bars". + >>> Foo.object.get(bars=bar) + ``get_latest_by`` ----------------- diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 277e9d379a..29700f4393 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -704,6 +704,34 @@ longer than the 4000 byte limit of ``NVARCHAR2``, you should use ``TextField`` field (e.g. annotating the model with an aggregation or using ``distinct()``) you'll need to change them (to defer the field). +Using a model name as a query lookup when ``default_related_name`` is set +------------------------------------------------------------------------- + +Assume the following models:: + + from django.db import models + + class Foo(models.Model): + pass + + class Bar(models.Model): + foo = models.ForeignKey(Foo) + + class Meta: + default_related_name = 'bars' + +In older versions, :attr:`~django.db.models.Options.default_related_name` +couldn't be used as a query lookup. This is fixed and support for the old +lookup name is deprecated. For example, since ``default_related_name`` is set +in model ``Bar``, instead of using the model name ``bar`` as the lookup:: + + >>> bar = Bar.objects.get(pk=1) + >>> Foo.object.get(bar=bar) + +use the default_related_name ``bars``:: + + >>> Foo.object.get(bars=bar) + Miscellaneous ------------- |
