Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Delete method related object behavior is wrong #9
If you have two models that inherit from the logicaldelete Model one with a GenericForeignKey pointing to the other and the other with a GenericRelation for the type of the other with a
With this setup, if you delete a post, all comments and likes pointing to it will be deleted. If you delete a like or a comment, the corresponding post will not be deleted. This is correct and expected behavior. Here's the same example but with the Comment and Post models (but not the Like model) inheriting from the django-logicaldelete model.
With this setup, if you delete a post, neither its likes nor comments will be deleted (opposite of expected behavior). If you delete a like, its post will not be deleted (expected behavior). If you delete a comment, the corresponding post will be deleted (opposite of expected behavior).
You can just imagine the code for this next example but if you make the Post model inherit from Django's Model, not logicaldelete's Model, but leave Comment inheriting from logicaldelete's Model, when you delete a comment, the corresponding post is not deleted (expected behavior). When you delete a post, any corresponding comments are actually, not logically, deleted. That's a separate issue from this one but something I came across in the process.
Back to the issue at hand. I discovered this because when I added functionality to delete comments to my app, posts started getting deleted. The silver lining was that since my posts model was using logicaldelete I was able to restore them after I quickly discovered the problem.