Return a list of the most related objects to instance.
351264
def get_related(self, instance, number):
        
        related_pks = self.compute_related(instance.pk)[:number]
        related_pks = [pk for pk, score in related_pks]
        related_objects = sorted(
            self.queryset.model.objects.filter(pk__in=related_pks),
            key=lambda x: related_pks.index(x.pk))
        return related_objects
710678
def _get_instances(self, instance):
        

        return [
            x
            for x in self.tree.body
            if isinstance(x, instance)
        ]
868826
def get_objects_of_class(cls):
        
        return list(o for o in gc.get_objects() if isinstance(o, cls))
1275821
def get_objects_with_object(self, obj_type, *child_types):
        

        return [o for o in self.get_objects_by_type(obj_type) if
                o.get_objects_by_type(*child_types)]
1151853
def get(self, instance_ids=None, filters=None):
        """"""
        params = {}
        if filters:
            params["filters"] = make_filters(filters)
        if instance_ids:
            params['InstanceIds'] = instance_ids
        reservations = self.call("DescribeInstances",
                                 response_data_key="Reservations",
                                 **params)
        if reservations:
            return list(chain(*(r["Instances"] for r in reservations)))
        return []
76890
def get_objects(self):
        
        objects = {}
        for key in six.iterkeys(self.form_classes):
            objects[key] = None
        return objects
1058497
def get_related(self, instance, number):
        
        cache = self.cache
        cache_key = '%s:%s' % (instance.pk, number)
        if cache_key not in cache:
            related_objects = super(CachedModelVectorBuilder,
                                    self).get_related(instance, number)
            cache[cache_key] = related_objects
            self.cache = cache
        return cache[cache_key]
1174140
def sort(self):
        """"""
        super(JSSObjectList, self).sort(key=lambda k: k.id)
594535
def relations():
    """"""
    rels = {}
    for reltype in relation_types():
        relids = {}
        for relid in relation_ids(reltype):
            units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
            for unit in related_units(relid):
                reldata = relation_get(unit=unit, rid=relid)
                units[unit] = reldata
            relids[relid] = units
        rels[reltype] = relids
    return rels
8001
def to_dict(self):
        """"""
        out = {}

        fields = self.__class__.search_objects.mapping.properties.properties

        for key in fields:
            # TODO: What if we've mapped the property to a different name? Will we allow that?

            attribute = getattr(self, key)

            field = fields[key]

            # I believe this should take the highest priority.
            if hasattr(field, "to_es"):
                out[key] = field.to_es(attribute)

            # First we check it this is a manager, in which case we have many related objects
            elif isinstance(attribute, models.Manager):
                if issubclass(attribute.model, Indexable):
                    # TODO: We want this to have some awareness of the relevant field.
                    out[key] = [obj.to_dict() for obj in attribute.all()]
                else:
                    out[key] = list(attribute.values_list("pk", flat=True))

            elif callable(attribute):
                out[key] = attribute()

            elif isinstance(attribute, Indexable):
                out[key] = attribute.to_dict()
            else:
                out[key] = attribute

            if out[key] is None:
                del out[key]
        return out
486673
def get_many(self, ids):
        """"""
        return [self.instance(id, **fields)
                    for id, fields in zip(ids, self.api.mget(ids))]
267905
def get_related(self):
        
        # Fresh start
        self.related = False
        try:
            for interface in self.interfaces:
                if relation_ids(interface):
                    self.related = True
            return self.related
        except AttributeError as e:
            log("{} {}"
                "".format(self, e), 'INFO')
            return self.related
40952
def collect_related(self, finder_funcs, obj, count, *args, **kwargs):
        
        collected = []
        for func in finder_funcs:
            gathered = func(obj, count, collected, *args, **kwargs)
            if gathered:
                collected += gathered
            if len(collected) >= count:
                return collected[:count]

        return collected
341803
def get_instances(device_owners=None, vnic_type=None, instance_id=None):
    """"""
    session = db.get_reader_session()
    with session.begin():
        port_model = models_v2.Port
        binding_model = ml2_models.PortBinding
        instances = (session
                     .query(port_model,
                            binding_model)
                     .outerjoin(
                         binding_model,
                         port_model.id == binding_model.port_id)
                     .distinct(port_model.device_id)
                     .group_by(port_model.device_id)
                     .filter_unnecessary_ports(device_owners, vnic_type))
        if instance_id:
            instances = instances.filter(port_model.device_id == instance_id)
    return instances.all()
1225913
def get_objects(self):
        """"""
        return rope.base.oi.soi.get_passed_objects(
            self.pyfunction, self.index)
119387
def selected_objects(self):
        """"""

        return [
            obj
            for obj in self.text_objects
            if contains_or_overlap(self.table_bbox, obj.bbox)
        ]
459867
def get_all_related_many_to_many_objects(opts):
    
    if django.VERSION < (1, 9):
        return opts.get_all_related_many_to_many_objects()
    else:
        return [r for r in opts.related_objects if r.field.many_to_many]