I have three related models - Document, Collection, and CollectionDocument.
A Collection object is made up of a group of documents.

class Document(Model):
    document_id = models.AutoField(primary_key=True)
class Collection(Model):
    collection_id = models.AutoField(primary_key=True)
    document = models.ManyToManyField(Document,
through='CollectionDocument', related_name='collections',)
class CollectionDocument(Model):
    collection_id = models.ForeignKey(Collection, on_delete=models.CASCADE, )
    document = models.ForeignKey(Document, on_delete=models.CASCADE, )

In the Djangop Admin, I have a DocumentAdmin and a CollectionAdmin with the
CollectionDocument as inlines in the CollectionAdmin.

When I delete all the documents associated with a Collection, I also want
the Collection to be deleted. Right now, when I delete the documents in a
Collection, the CollectioDocument is empty, but the Collection still exists
without any documents associated with it.

I have tried several ways to do it using pre- and post-delete signals for
the CollectionDocument model, but nothing seems to work. Have I structured
my models incorrectly? How do I get the Collection to be deleted when all
the associated Documents are deleted?

Thanks!

Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2MBD3gH5h7m2YAp8zW%2Bi1cPC%2B-jFbnFmDUiTnVZZwYgBg%40mail.gmail.com.

Reply via email to