'Add \'objs\' to the collection of objects to be deleted as well as all
parent instances.  \'objs\' must be a homogeneous 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.)
If \'keep_parents\' is True, data of parent model\'s will be not deleted.'

def collect(self, objs, source=None, nullable=False, collect_related=True, source_attr=None, reverse_dependency=False, keep_parents=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__
    if (not keep_parents):
        concrete_model = model._meta.concrete_model
        for ptr in concrete_model._meta.parents.values():
            if ptr:
                parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
                self.collect(parent_objs, source=model, source_attr=ptr.remote_field.related_name, collect_related=False, reverse_dependency=True)
    if collect_related:
        parents = model._meta.parents
        for related in get_candidate_relations_to_delete(model._meta):
            if (keep_parents and (related.model in parents)):
                continue
            field = related.field
            if (field.remote_field.on_delete == DO_NOTHING):
                continue
            batches = self.get_del_batches(new_objs, field)
            for batch in batches:
                sub_objs = self.related_objects(related, batch)
                if self.can_fast_delete(sub_objs, from_field=field):
                    self.fast_deletes.append(sub_objs)
                elif sub_objs:
                    field.remote_field.on_delete(self, field, sub_objs, self.using)
        for field in model._meta.private_fields:
            if hasattr(field, 'bulk_related_objects'):
                sub_objs = field.bulk_related_objects(new_objs, self.using)
                self.collect(sub_objs, source=model, nullable=True)
