'Adds \'objs\' to the collection of objects to be deleted as well as all
parent instances.  \'objs\' must be a homogenous iterable collection of
model instances (e.g. a QuerySet).  If \'collect_related\' is True,
related objects will be handled by their respective on_delete handler.
If the call is the result of a cascade, \'source\' should be the model
that caused it and \'nullable\' should be set to True, if the relation
can be null.
If \'reverse_dependency\' is True, \'source\' will be deleted before the
current model, rather than after. (Needed for cascading to parent
models, the one case in which the cascade follows the forwards
direction of an FK rather than the reverse direction.)'

def collect(self, objs, source=None, nullable=False, collect_related=True, source_attr=None, reverse_dependency=False):

    if self.can_fast_delete(objs):
        self.fast_deletes.append(objs)
        return
    new_objs = self.add(objs, source, nullable, reverse_dependency=reverse_dependency)
    if (not new_objs):
        return
    model = new_objs[0].__class__
    concrete_model = model._meta.concrete_model
    for ptr in six.itervalues(concrete_model._meta.parents):
        if ptr:
            parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
            self.collect(parent_objs, source=model, source_attr=ptr.rel.related_name, collect_related=False, reverse_dependency=True)
    if collect_related:
        for related in model._meta.get_all_related_objects(include_hidden=True, include_proxy_eq=True):
            field = related.field
            if (field.rel.on_delete == DO_NOTHING):
                continue
            sub_objs = self.related_objects(related, new_objs)
            if self.can_fast_delete(sub_objs, from_field=field):
                self.fast_deletes.append(sub_objs)
            elif sub_objs:
                field.rel.on_delete(self, field, sub_objs, self.using)
        for field in model._meta.virtual_fields:
            if hasattr(field, 'bulk_related_objects'):
                sub_objs = field.bulk_related_objects(new_objs, self.using)
                self.collect(sub_objs, source=model, source_attr=field.rel.related_name, nullable=True)
