Ticket #10738: deferred_model_contenttype.diff

File deferred_model_contenttype.diff, 1.2 KB (added by tomasz.elendt, 6 years ago)
  • django/contrib/contenttypes/models.py

     
    1515        for the same model don't hit the database.
    1616        """
    1717        opts = model._meta
    18         key = (opts.app_label, opts.object_name.lower())
     18        if model._deferred:
     19            model_name = opts.proxy_for_model._meta.object_name.lower()
     20            name = smart_unicode(opts.proxy_for_model._meta.verbose_name_raw)
     21        else:
     22            model_name = opts.object_name.lower()
     23            name = smart_unicode(opts.verbose_name_raw)
     24        key = (opts.app_label, model_name)
    1925        try:
    2026            ct = self.__class__._cache[key]
    2127        except KeyError:
     
    2430            # django.utils.functional.__proxy__ object.
    2531            ct, created = self.get_or_create(
    2632                app_label = opts.app_label,
    27                 model = opts.object_name.lower(),
    28                 defaults = {'name': smart_unicode(opts.verbose_name_raw)},
     33                model = model_name,
     34                defaults = {'name': name},
    2935            )
    3036            self._add_to_cache(ct)
    3137           
Back to Top