Esempio n. 1
0
 def _fill_related_many_to_many_cache(self):
     cache = OrderedDict()
     parent_list = self.get_parent_list()
     for parent in self.parents:
         for obj, model in parent._meta.get_all_related_m2m_objects_with_model():
             if obj.field.creation_counter < 0 and obj.model not in parent_list:
                 continue
             if not model:
                 cache[obj] = parent
             else:
                 cache[obj] = model
     for klass in self.app_cache.get_models(only_installed=False):
         if not klass._meta.swapped:
             for f in klass._meta.local_many_to_many:
                 if (f.rel
                         and not isinstance(f.rel.to, six.string_types)
                         and self == f.rel.to._meta):
                     cache[f.related] = None
     if app_cache.app_cache_ready():
         self._related_many_to_many_cache = cache
     return cache
Esempio n. 2
0
 def init_name_map(self):
     """
     Initialises the field name -> field object mapping.
     """
     cache = {}
     # We intentionally handle related m2m objects first so that symmetrical
     # m2m accessor names can be overridden, if necessary.
     for f, model in self.get_all_related_m2m_objects_with_model():
         cache[f.field.related_query_name()] = (f, model, False, True)
     for f, model in self.get_all_related_objects_with_model():
         cache[f.field.related_query_name()] = (f, model, False, False)
     for f, model in self.get_m2m_with_model():
         cache[f.name] = cache[f.attname] = (f, model, True, True)
     for f, model in self.get_fields_with_model():
         cache[f.name] = cache[f.attname] = (f, model, True, False)
     for f in self.virtual_fields:
         if hasattr(f, 'related'):
             cache[f.name] = cache[f.attname] = (
                 f.related, None if f.model == self.model else f.model, True, False)
     if app_cache.app_cache_ready():
         self._name_map = cache
     return cache