diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index d588ff4..f3543b3 100644
|
a
|
b
|
def get_by_natural_key(self, app_label, model):
|
| 17 | 17 | return ct |
| 18 | 18 | |
| 19 | 19 | def _get_opts(self, model): |
| 20 | | return model._meta.concrete_model._meta |
| | 20 | if model._deferred: |
| | 21 | # Deferred models shouldn't have their own content type since |
| | 22 | # they're only dynamic wrappers to allow field deferring. |
| | 23 | # We make sure to retreive options from the model they are proxying |
| | 24 | # which can also be a proxy. |
| | 25 | model = model._meta.proxy_for_model |
| | 26 | return model._meta |
| 21 | 27 | |
| 22 | 28 | def _get_from_cache(self, opts): |
| 23 | 29 | key = (opts.app_label, opts.object_name.lower()) |
diff --git a/tests/modeltests/proxy_models/tests.py b/tests/modeltests/proxy_models/tests.py
index b332103..18a578a 100644
|
a
|
b
|
def _handler(*args, **kwargs):
|
| 217 | 217 | signals.post_save.disconnect(h6, sender=MyPersonProxy) |
| 218 | 218 | |
| 219 | 219 | def test_content_type(self): |
| | 220 | # A model and a proxy of this model do not |
| | 221 | # share the same ContentType see #17648 |
| 220 | 222 | ctype = ContentType.objects.get_for_model |
| 221 | | self.assertTrue(ctype(Person) is ctype(OtherPerson)) |
| | 223 | self.assertFalse(ctype(Person) is ctype(OtherPerson)) |
| 222 | 224 | |
| 223 | 225 | def test_user_userproxy_userproxyproxy(self): |
| 224 | 226 | User.objects.create(name='Bruce') |
diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py
index 4afe39b..4e4d80c 100644
|
a
|
b
|
def test_only_and_defer_usage_on_proxy_models(self):
|
| 169 | 169 | self.assertEqual(dp.name, proxy.name, msg=msg) |
| 170 | 170 | self.assertEqual(dp.value, proxy.value, msg=msg) |
| 171 | 171 | |
| | 172 | # Instances of proxy models with deferred fields should |
| | 173 | # return the content type of the proxy model (bug #17648) |
| | 174 | ctype = ContentType.objects.get_for_model |
| | 175 | c1 = ctype(Proxy.objects.all()[0]) |
| | 176 | c2 = ctype(Proxy.objects.defer("name")[0]) |
| | 177 | c3 = ctype(Proxy.objects.only("name")[0]) |
| | 178 | self.assertTrue(c1 is c2 is c3) |
| | 179 | |
| 172 | 180 | def test_resolve_columns(self): |
| 173 | 181 | rt = ResolveThis.objects.create(num=5.0, name='Foobar') |
| 174 | 182 | qs = ResolveThis.objects.defer('num') |