Refs #21414 -- Removed Field.related per deprecation timeline.

This commit is contained in:
Tim Graham 2015-09-01 11:02:08 -04:00
parent f1761e3fef
commit 96317ad8de
2 changed files with 1 additions and 25 deletions

View File

@ -12,9 +12,7 @@ from django.db.models.deletion import CASCADE, SET_DEFAULT, SET_NULL
from django.db.models.query_utils import PathInfo from django.db.models.query_utils import PathInfo
from django.db.models.utils import make_model_tuple from django.db.models.utils import make_model_tuple
from django.utils import six from django.utils import six
from django.utils.deprecation import ( from django.utils.deprecation import RemovedInDjango20Warning
RemovedInDjango20Warning, RemovedInDjango110Warning,
)
from django.utils.encoding import force_text, smart_text from django.utils.encoding import force_text, smart_text
from django.utils.functional import cached_property, curry from django.utils.functional import cached_property, curry
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -358,13 +356,6 @@ class RelatedField(Field):
self.verbose_name = self.remote_field.model._meta.verbose_name self.verbose_name = self.remote_field.model._meta.verbose_name
self.remote_field.set_field_name() self.remote_field.set_field_name()
@property
def related(self):
warnings.warn(
"Usage of field.related has been deprecated. Use field.remote_field instead.",
RemovedInDjango110Warning, 2)
return self.remote_field
def do_related_class(self, other, cls): def do_related_class(self, other, cls):
self.set_attributes_from_rel() self.set_attributes_from_rel()
self.contribute_to_related_class(other, self.remote_field) self.contribute_to_related_class(other, self.remote_field)

View File

@ -1,13 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import threading import threading
import warnings
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections
from django.db.models.fields import Field from django.db.models.fields import Field
from django.db.models.fields.related import ForeignObjectRel
from django.db.models.manager import BaseManager from django.db.models.manager import BaseManager
from django.db.models.query import EmptyQuerySet, QuerySet from django.db.models.query import EmptyQuerySet, QuerySet
from django.test import ( from django.test import (
@ -771,16 +769,3 @@ class ModelRefreshTests(TestCase):
a = Article.objects.create(pub_date=self._truncate_ms(datetime.now())) a = Article.objects.create(pub_date=self._truncate_ms(datetime.now()))
with self.assertNumQueries(0): with self.assertNumQueries(0):
a.refresh_from_db(fields=[]) a.refresh_from_db(fields=[])
class TestRelatedObjectDeprecation(SimpleTestCase):
def test_field_related_deprecation(self):
field = SelfRef._meta.get_field('selfref')
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
self.assertIsInstance(field.related, ForeignObjectRel)
self.assertEqual(len(warns), 1)
self.assertEqual(
str(warns.pop().message),
'Usage of field.related has been deprecated. Use field.remote_field instead.'
)