Index: django/contrib/contenttypes/generic.py
===================================================================
--- django/contrib/contenttypes/generic.py	(revisión: 6403)
+++ django/contrib/contenttypes/generic.py	(copia de trabajo)
@@ -11,23 +11,25 @@
 from django.dispatch import dispatcher
 from django.utils.functional import curry
 
+CONTENT_TYPE_CACHE = {}
+
 class GenericForeignKey(object):
     """
     Provides a generic relation to any object through content-type/object-id
     fields.
     """
-    
+
     def __init__(self, ct_field="content_type", fk_field="object_id"):
         self.ct_field = ct_field
         self.fk_field = fk_field
-        
+
     def contribute_to_class(self, cls, name):
         # Make sure the fields exist (these raise FieldDoesNotExist, 
         # which is a fine error to raise here)
         self.name = name
         self.model = cls
         self.cache_attr = "_%s_cache" % name
-        
+
         # For some reason I don't totally understand, using weakrefs here doesn't work.
         dispatcher.connect(self.instance_pre_init, signal=signals.pre_init, sender=cls, weak=False)
 
@@ -36,17 +38,17 @@
 
     def instance_pre_init(self, signal, sender, args, kwargs):
         # Handle initalizing an object with the generic FK instaed of 
-        # content-type/object-id fields.        
+        # content-type/object-id fields.
         if self.name in kwargs:
             value = kwargs.pop(self.name)
             kwargs[self.ct_field] = self.get_content_type(value)
             kwargs[self.fk_field] = value._get_pk_val()
-            
+
     def get_content_type(self, obj):
         # Convenience function using get_model avoids a circular import when using this model
         ContentType = get_model("contenttypes", "contenttype")
         return ContentType.objects.get_for_model(obj)
-        
+
     def __get__(self, instance, instance_type=None):
         if instance is None:
             raise AttributeError, u"%s must be accessed via instance" % self.name
@@ -55,7 +57,13 @@
             return getattr(instance, self.cache_attr)
         except AttributeError:
             rel_obj = None
-            ct = getattr(instance, self.ct_field)
+            ct_id_fieldname = instance._meta.get_field(self.ct_field).get_attname()
+            ct_id = getattr(instance, ct_id_fieldname)
+            try:
+                ct = CONTENT_TYPE_CACHE[ct_id]
+            except KeyError:
+                ct = getattr(instance, self.ct_field)
+                CONTENT_TYPE_CACHE[ct_id] = ct
             if ct:
                 try:
                     rel_obj = ct.get_object_for_this_type(pk=getattr(instance, self.fk_field))
@@ -77,7 +85,7 @@
         setattr(instance, self.ct_field, ct)
         setattr(instance, self.fk_field, fk)
         setattr(instance, self.cache_attr, value)
-    
+
 class GenericRelation(RelatedField, Field):
     """Provides an accessor to generic related objects (i.e. comments)"""
 
@@ -90,8 +98,8 @@
                             
         # Override content-type/object-id field names on the related class
         self.object_id_field_name = kwargs.pop("object_id_field", "object_id")
-        self.content_type_field_name = kwargs.pop("content_type_field", "content_type")                
-        
+        self.content_type_field_name = kwargs.pop("content_type_field", "content_type")
+
         kwargs['blank'] = True
         kwargs['editable'] = False
         kwargs['serialize'] = False
@@ -116,7 +124,7 @@
 
     def m2m_column_name(self):
         return self.object_id_field_name
-        
+
     def m2m_reverse_name(self):
         return self.object_id_field_name
 
@@ -131,13 +139,13 @@
 
     def contribute_to_related_class(self, cls, related):
         pass
-        
+
     def set_attributes_from_rel(self):
         pass
 
     def get_internal_type(self):
         return "ManyToManyField"
-        
+
 class ReverseGenericRelatedObjectsDescriptor(object):
     """
     This class provides the functionality that makes the related-object
@@ -193,12 +201,12 @@
     Factory function for a manager that subclasses 'superclass' (which is a
     Manager) and adds behavior for generic related objects.
     """
-    
+
     class GenericRelatedObjectManager(superclass):
         def __init__(self, model=None, core_filters=None, instance=None, symmetrical=None,
                      join_table=None, source_col_name=None, target_col_name=None, content_type=None,
                      content_type_field_name=None, object_id_field_name=None):
-            
+
             super(GenericRelatedObjectManager, self).__init__()
             self.core_filters = core_filters or {}
             self.model = model
@@ -212,7 +220,7 @@
             self.content_type_field_name = content_type_field_name
             self.object_id_field_name = object_id_field_name
             self.pk_val = self.instance._get_pk_val()
-                        
+
         def get_query_set(self):
             query = {
                 '%s__pk' % self.content_type_field_name : self.content_type.id, 
