1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

Refs #24099 -- Removed compatibility shim for ContentType.name field.

This commit is contained in:
Tim Graham 2015-09-03 14:57:57 -04:00
parent a3fe4addcb
commit 75374d3797
3 changed files with 0 additions and 37 deletions

View File

@ -1,11 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.apps import apps from django.apps import apps
from django.db import models from django.db import models
from django.db.utils import IntegrityError, OperationalError, ProgrammingError from django.db.utils import IntegrityError, OperationalError, ProgrammingError
from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -36,14 +33,6 @@ class ContentTypeManager(models.Manager):
key = (opts.app_label, opts.model_name) key = (opts.app_label, opts.model_name)
return self.__class__._cache[self.db][key] return self.__class__._cache[self.db][key]
def create(self, **kwargs):
if 'name' in kwargs:
del kwargs['name']
warnings.warn(
"ContentType.name field doesn't exist any longer. Please remove it from your code.",
RemovedInDjango110Warning, stacklevel=2)
return super(ContentTypeManager, self).create(**kwargs)
def get_for_model(self, model, for_concrete_model=True): def get_for_model(self, model, for_concrete_model=True):
""" """
Returns the ContentType object for a given model, creating the Returns the ContentType object for a given model, creating the

View File

@ -82,11 +82,6 @@ The ``ContentType`` model
:attr:`verbose_name <django.db.models.Field.verbose_name>` :attr:`verbose_name <django.db.models.Field.verbose_name>`
attribute of the model. attribute of the model.
.. versionchanged:: 1.8
Before Django 1.8, the ``name`` property was a real field on the
``ContentType`` model.
Let's look at an example to see how this works. If you already have Let's look at an example to see how this works. If you already have
the :mod:`~django.contrib.contenttypes` application installed, and then add the :mod:`~django.contrib.contenttypes` application installed, and then add
:mod:`the sites application <django.contrib.sites>` to your :mod:`the sites application <django.contrib.sites>` to your

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.views import shortcut from django.contrib.contenttypes.views import shortcut
from django.contrib.sites.shortcuts import get_current_site from django.contrib.sites.shortcuts import get_current_site
@ -247,25 +245,6 @@ class ContentTypesTests(TestCase):
ct_fetched = ContentType.objects.get_for_id(ct.pk) ct_fetched = ContentType.objects.get_for_id(ct.pk)
self.assertIsNone(ct_fetched.model_class()) self.assertIsNone(ct_fetched.model_class())
def test_name_deprecation(self):
"""
ContentType.name has been removed. Test that a warning is emitted when
creating a ContentType with a `name`, but the creation should not fail.
"""
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
ContentType.objects.create(
name='Name',
app_label='contenttypes',
model='OldModel',
)
self.assertEqual(len(warns), 1)
self.assertEqual(
str(warns[0].message),
"ContentType.name field doesn't exist any longer. Please remove it from your code."
)
self.assertTrue(ContentType.objects.filter(model='OldModel').exists())
@mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get_or_create') @mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get_or_create')
@mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get') @mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get')
def test_message_if_get_for_model_fails(self, mocked_get, mocked_get_or_create): def test_message_if_get_for_model_fails(self, mocked_get, mocked_get_or_create):