Ejemplo n.º 1
0
 def _fill_related_objects_cache(self):
     cache = OrderedDict()
     parent_list = self.get_parent_list()
     for parent in self.parents:
         for obj, model in parent._meta.get_all_related_objects_with_model(
                 include_hidden=True):
             if (obj.field.creation_counter < 0 or obj.field.rel.parent_link
                 ) and obj.model not in parent_list:
                 continue
             if not model:
                 cache[obj] = parent
             else:
                 cache[obj] = model
     # Collect also objects which are in relation to some proxy child/parent of self.
     proxy_cache = cache.copy()
     for klass in self.app_cache.get_models(include_auto_created=True,
                                            only_installed=False):
         if not klass._meta.swapped:
             for f in klass._meta.local_fields:
                 if f.rel and not isinstance(
                         f.rel.to,
                         six.string_types) and f.generate_reverse_relation:
                     if self == f.rel.to._meta:
                         cache[f.related] = None
                         proxy_cache[f.related] = None
                     elif self.concrete_model == f.rel.to._meta.concrete_model:
                         proxy_cache[f.related] = None
     self._related_objects_cache = cache
     self._related_objects_proxy_cache = proxy_cache
Ejemplo n.º 2
0
 def _fill_related_objects_cache(self):
     cache = OrderedDict()
     parent_list = self.get_parent_list()
     for parent in self.parents:
         for obj, model in parent._meta.get_all_related_objects_with_model(include_hidden=True):
             if (obj.field.creation_counter < 0 or obj.field.rel.parent_link) and obj.model not in parent_list:
                 continue
             if not model:
                 cache[obj] = parent
             else:
                 cache[obj] = model
     # Collect also objects which are in relation to some proxy child/parent of self.
     proxy_cache = cache.copy()
     for klass in self.app_cache.get_models(include_auto_created=True, only_installed=False):
         if not klass._meta.swapped:
             for f in klass._meta.local_fields:
                 if f.rel and not isinstance(f.rel.to, six.string_types) and f.generate_reverse_relation:
                     if self == f.rel.to._meta:
                         cache[f.related] = None
                         proxy_cache[f.related] = None
                     elif self.concrete_model == f.rel.to._meta.concrete_model:
                         proxy_cache[f.related] = None
     self._related_objects_cache = cache
     self._related_objects_proxy_cache = proxy_cache