san4ezy / django_softdelete

MIT License
79 stars 21 forks source link

Use the related models on_delete setting #15

Closed epicserve closed 9 months ago

epicserve commented 1 year ago

It would be good to honor each related model's on_delete setting rather than a global on_delete setting. For example, if you had the following models.

class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    author = models.ForeignKeyField(Author, on_delete=models.RESTRICT)

If you tried to delete the author and the author was used in a book, it shouldn't allow the deleting because there are models that use that author.

san4ezy commented 1 year ago

Thank you @epicserve ! Yep, good catch. I'll try to add this functionality with the very next update.

san4ezy commented 9 months ago

Hi @epicserve , the latest version of this lib is already can use on_delete option as well. You could use it as a regular Django model. But pay attention, this functionality works only if all related models are SoftDeleteModel.

I close this issue. But If you still have some questions, feel free to open it again.