From f619b72815fd8d0bb6f65921ef07ac4bc8a12e29 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 14 Jan 2016 07:24:25 -0500 Subject: [PATCH] [1.9.x] Fixed #26078 -- Clarified "old vs. new" in model._meta upgrade guide. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Thomas Güttler for the suggestion. Backport of 28acc0d6df844ccfc8de6f4e7d5883eb4841e946 from master --- docs/ref/models/meta.txt | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/ref/models/meta.txt b/docs/ref/models/meta.txt index d8f711b810..e92cd9b971 100644 --- a/docs/ref/models/meta.txt +++ b/docs/ref/models/meta.txt @@ -172,7 +172,7 @@ that were previously excluded - will almost certainly result in better code. Assuming you have a model named ``MyModel``, the following substitutions can be made to convert your code to the new API: -* ``MyModel._meta.get_field(name)``:: +* ``MyModel._meta.get_field(name)`` becomes:: f = MyModel._meta.get_field(name) @@ -185,10 +185,8 @@ can be made to convert your code to the new API: ``get_field()`` API will find :class:`~django.contrib.contenttypes.fields.GenericForeignKey` relations; -* ``MyModel._meta.get_field_by_name(name)``: - - ``get_field_by_name()`` returned four values: - ``(field, model, direct, m2m)``: +* ``MyModel._meta.get_field_by_name(name)`` returns a tuple of these four + values with the following replacements: - ``field`` can be found by ``MyModel._meta.get_field(name)`` @@ -206,7 +204,7 @@ can be made to convert your code to the new API: - ``m2m`` can be found through the :attr:`~django.db.models.Field.many_to_many` attribute on the field. -* ``MyModel._meta.get_fields_with_model()``:: +* ``MyModel._meta.get_fields_with_model()`` becomes:: [ (f, f.model if f.model != MyModel else None) @@ -216,7 +214,7 @@ can be made to convert your code to the new API: or (f.many_to_one and f.related_model) ] -* ``MyModel._meta.get_concrete_fields_with_model()``:: +* ``MyModel._meta.get_concrete_fields_with_model()`` becomes:: [ (f, f.model if f.model != MyModel else None) @@ -228,7 +226,7 @@ can be made to convert your code to the new API: ) ] -* ``MyModel._meta.get_m2m_with_model()``:: +* ``MyModel._meta.get_m2m_with_model()`` becomes:: [ (f, f.model if f.model != MyModel else None) @@ -236,14 +234,14 @@ can be made to convert your code to the new API: if f.many_to_many and not f.auto_created ] -* ``MyModel._meta.get_all_related_objects()``:: +* ``MyModel._meta.get_all_related_objects()`` becomes:: [ f for f in MyModel._meta.get_fields() if (f.one_to_many or f.one_to_one) and f.auto_created ] -* ``MyModel._meta.get_all_related_objects_with_model()``:: +* ``MyModel._meta.get_all_related_objects_with_model()`` becomes:: [ (f, f.model if f.model != MyModel else None) @@ -251,14 +249,14 @@ can be made to convert your code to the new API: if (f.one_to_many or f.one_to_one) and f.auto_created ] -* ``MyModel._meta.get_all_related_many_to_many_objects()``:: +* ``MyModel._meta.get_all_related_many_to_many_objects()`` becomes:: [ f for f in MyModel._meta.get_fields(include_hidden=True) if f.many_to_many and f.auto_created ] -* ``MyModel._meta.get_all_related_m2m_objects_with_model()``:: +* ``MyModel._meta.get_all_related_m2m_objects_with_model()`` becomes:: [ (f, f.model if f.model != MyModel else None) @@ -266,7 +264,7 @@ can be made to convert your code to the new API: if f.many_to_many and f.auto_created ] -* ``MyModel._meta.get_all_field_names()``:: +* ``MyModel._meta.get_all_field_names()`` becomes:: from itertools import chain list(set(chain.from_iterable(