Add 'objs' to the collection of objects to be deleted. 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. Return a list of all objects that were not already collected
(self, objs, source=None, nullable=False, reverse_dependency=False)
| 139 | self.dependencies = defaultdict(set) # {model: {models}} |
| 140 | |
| 141 | def add(self, objs, source=None, nullable=False, reverse_dependency=False): |
| 142 | """ |
| 143 | Add 'objs' to the collection of objects to be deleted. If the call is |
| 144 | the result of a cascade, 'source' should be the model that caused it, |
| 145 | and 'nullable' should be set to True if the relation can be null. |
| 146 | |
| 147 | Return a list of all objects that were not already collected. |
| 148 | """ |
| 149 | if not objs: |
| 150 | return [] |
| 151 | new_objs = [] |
| 152 | model = objs[0].__class__ |
| 153 | instances = self.data[model] |
| 154 | for obj in objs: |
| 155 | if obj not in instances: |
| 156 | new_objs.append(obj) |
| 157 | instances.update(new_objs) |
| 158 | # Nullable relationships can be ignored -- they are nulled out before |
| 159 | # deleting, and therefore do not affect the order in which objects have |
| 160 | # to be deleted. |
| 161 | if source is not None and not nullable: |
| 162 | self.add_dependency(source, model, reverse_dependency=reverse_dependency) |
| 163 | return new_objs |
| 164 | |
| 165 | def add_dependency(self, model, dependency, reverse_dependency=False): |
| 166 | if reverse_dependency: |
no test coverage detected