diff options
Diffstat (limited to 'django/contrib/contenttypes/models.py')
| -rw-r--r-- | django/contrib/contenttypes/models.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index f0bd109b00..34d54441fe 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -118,11 +118,13 @@ class ContentTypeManager(models.Manager): def _add_to_cache(self, using, ct): """Insert a ContentType into the cache.""" - model = ct.model_class() - key = (model._meta.app_label, model._meta.model_name) + # Note it's possible for ContentType objects to be stale; model_class() will return None. + # Hence, there is no reliance on model._meta.app_label here, just using the model fields instead. + key = (ct.app_label, ct.model) self.__class__._cache.setdefault(using, {})[key] = ct self.__class__._cache.setdefault(using, {})[ct.id] = ct + @python_2_unicode_compatible class ContentType(models.Model): name = models.CharField(max_length=100) @@ -153,7 +155,6 @@ class ContentType(models.Model): def model_class(self): "Returns the Python model class for this type of content." - from django.db import models return models.get_model(self.app_label, self.model, only_installed=False) |
