+ return getattr(model_instance, self.attname)
+
+
+# Add a post-save signal function to run the syncer.
+def post_save_embed_sync(sender, instance, **kwargs):
+ if hasattr(instance, '_embedded_instances') and instance._embedded_instances:
+ sync_embedded_instances(instance, instance._embedded_instances)
+models.signals.post_save.connect(post_save_embed_sync)
+
+
+# Deletions can't cascade automatically without a GenericRelation - but there's no good way of
+# knowing what models should have one. Anything can be embedded! Also, cascading would probably
+# bypass the Embed model's delete method.
+def post_delete_cascade(sender, instance, **kwargs):
+ ct = ContentType.objects.get_for_model(sender)
+ embeds = Embed.objects.filter(embedded_content_type=ct, embedded_object_id=instance.id)
+ for embed in embeds:
+ embed.delete()
+ Embed.objects.filter(embedder_content_type=ct, embedder_object_id=instance.id).delete()
+models.signals.post_delete.connect(post_delete_cascade)