Ticket #17648: ticket-17648-correctly-handle-deferred-proxies.diff

File ticket-17648-correctly-handle-deferred-proxies.diff, 2.2 KB (added by Simon Charette, 13 years ago)
  • django/contrib/contenttypes/models.py

    diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
    index 1bb07e0..9ccadb0 100644
    a b def get_by_natural_key(self, app_label, model):  
    1717
    1818    def _get_opts(self, model):
    1919        opts = model._meta
    20         while opts.proxy:
    21             model = opts.proxy_for_model
    22             opts = model._meta
     20        if model._deferred:
     21            opts = model.__class__.__bases__[0]._meta
    2322        return opts
    2423
    2524    def _get_from_cache(self, opts):
  • tests/modeltests/proxy_models/tests.py

    diff --git a/tests/modeltests/proxy_models/tests.py b/tests/modeltests/proxy_models/tests.py
    index 3ec8465..04ea203 100644
    a b def _handler(*args, **kwargs):  
    217217        signals.post_save.disconnect(h6, sender=MyPersonProxy)
    218218
    219219    def test_content_type(self):
     220        # A model and a proxy of this model do not
     221        # share the same ContentType see #17648
    220222        ctype = ContentType.objects.get_for_model
    221         self.assertTrue(ctype(Person) is ctype(OtherPerson))
     223        self.assertFalse(ctype(Person) is ctype(OtherPerson))
    222224
    223225    def test_user_userproxy_userproxyproxy(self):
    224226        User.objects.create(name='Bruce')
  • tests/regressiontests/defer_regress/tests.py

    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):  
    169169        self.assertEqual(dp.name, proxy.name, msg=msg)
    170170        self.assertEqual(dp.value, proxy.value, msg=msg)
    171171
     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
    172180    def test_resolve_columns(self):
    173181        rt = ResolveThis.objects.create(num=5.0, name='Foobar')
    174182        qs = ResolveThis.objects.defer('num')
Back to Top