def test_fast_delete_instance_set_pk_none(self): u = User.objects.create() # User can be fast-deleted. collector = Collector(using='default') self.assertTrue(collector.can_fast_delete(u)) u.delete() self.assertIsNone(u.pk)
def test_fast_delete_instance_set_pk_none(self): u = User.objects.create() # User can be fast-deleted. collector = Collector(using='default') self.assertTrue(collector.can_fast_delete(u)) u.delete() self.assertIsNone(u.pk)
def collect_related_instanses(entity, exclude_models=None): def always_false(*args, **kw): return False exclude_models = exclude_models or [] using = router.db_for_write(entity.__class__, instance=entity) collector = Collector(using=using) collector.can_fast_delete = always_false collector.collect([entity]) entities = [] models = set() for model, instances in collector.data.items(): if model not in exclude_models: entities.extend(instances) models.add(model) return entities, models
def related_classes(instance): """ Return all classes which would be deleted if the passed instance were deleted too by employing the cascade machinery of Django itself. Does **not** return instances, only classes. Note! When using Django 1.5, autogenerated models (many to many through models) are returned too. """ collector = Collector(using=instance._state.db) # We really do not want fast deletion, we absolutely need to know whether # there are related objects around! collector.can_fast_delete = lambda *args, **kwargs: False collector.collect([instance]) # Save collected objects for later referencing (well yes, it does return # instances but we don't have to tell anybody :-) instance._collected_objects = collector.data return collector.data.keys()
def related_classes(instance): """ Return all classes which would be deleted if the passed instance were deleted too by employing the cascade machinery of Django itself. Does **not** return instances, only classes. Note! When using Django 1.5, autogenerated models (many to many through models) are returned too. """ collector = Collector(using=instance._state.db) # We really do not want fast deletion, we absolutely need to know whether # there are related objects around! collector.can_fast_delete = lambda *args, **kwargs: False collector.collect([instance]) # Save collected objects for later referencing (well yes, it does return # instances but we don't have to tell anybody :-) instance._collected_objects = collector.data return collector.data.keys()