Update for proxy models and Django 1.5
Only monkeypatch when using Django < 1.5 Updated testfix_request_path_info
parent
e2cfbf3898
commit
74389bb23d
|
|
@ -6,6 +6,7 @@ Copyright:
|
|||
This code and affiliated files are (C) by Bert Constantin and individual contributors.
|
||||
Please see LICENSE and AUTHORS for more information.
|
||||
"""
|
||||
import django
|
||||
from polymorphic_model import PolymorphicModel
|
||||
from manager import PolymorphicManager
|
||||
from query import PolymorphicQuerySet
|
||||
|
|
@ -25,15 +26,12 @@ def get_version():
|
|||
version += ' %s' % VERSION[3]
|
||||
return version
|
||||
|
||||
|
||||
# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
|
||||
if django.VERSION[:2] < (1, 5):
|
||||
from django.contrib.contenttypes.models import ContentTypeManager
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
|
||||
# Monkey-patch Django to allow ContentTypes for proxy models. This is compatible with an
|
||||
# upcoming change in Django 1.5 and should be removed when we upgrade. There is a test
|
||||
# in MonkeyPatchTests that checks for this.
|
||||
# https://code.djangoproject.com/ticket/18399
|
||||
|
||||
def get_for_model(self, model, for_concrete_model=True):
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
|
|
|
|||
|
|
@ -750,9 +750,8 @@ class RegressionTests(TestCase):
|
|||
self.assertQuerysetEqual(Bottom.objects.all(), [repr(r) for r in expected_queryset])
|
||||
|
||||
|
||||
class MonkeyPatchTests(TestCase):
|
||||
|
||||
def test_content_types_for_proxy_models_patch(self):
|
||||
class ProxiedModelTests(TestCase):
|
||||
def test_content_types_for_proxy_models(self):
|
||||
from django.db.models import Model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
|
|
@ -766,20 +765,3 @@ class MonkeyPatchTests(TestCase):
|
|||
ct = ContentType.objects.get_for_model(Proxy, for_concrete_model=False)
|
||||
self.assertEqual(Proxy, ct.model_class())
|
||||
|
||||
def test_content_types_for_proxy_models_patch_still_required(self):
|
||||
"""
|
||||
If this test fails then our monkey patch of ContentTypeManager.get_for_model
|
||||
is no longer required and should be removed
|
||||
"""
|
||||
from django.db.models import Model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
class MyModel(Model):
|
||||
pass
|
||||
|
||||
self.assertRaisesMessage(
|
||||
TypeError,
|
||||
"get_for_model() got an unexpected keyword argument 'for_concrete_model'",
|
||||
ContentType.objects.get_for_model__original,
|
||||
MyModel, for_concrete_model=False
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue