I have created a model which attaches media to blog posts:
class MediaAttachment(models.Model):
media = models.ForeignKey(Media, related_name='attachment')
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField(db_index=True)
object = generic.GenericForeignKey('content_type', 'object_id')
It works well, but when if I attach some media to a blog entry and then delete that blog entry, the attachment to that entry remains in the MediaAttachment table. What would be the smartest way to GC the MediaAttachment tables? Is signals the best way to do this?
Ok, so I managed to make this work nicely using the following method.
I added this signal to my MediaAttachment model:
Then my delete method looks like this: