Explain the concept of soft deletes and how you would implement it conceptually in Django.
Last updated
A soft delete marks a row as deleted (e.g. a nullable
deleted_attimestamp) instead of removing it, so data stays recoverable. Overridedelete()to set the marker.Use a default custom manager that filters out deleted rows, plus a second manager (e.g.
all_objects) that sees everything.Gotchas: unique constraints need conditional/partial variants, cascades and admin or third-party code may bypass the manager, and data grows forever without periodic purging.
- https://www.geeksforgeeks.org/python/djangos-soft-delete-simplifying-data-management/
- https://www.techfliez.com/django-delete-data
- https://www.tomisin.dev/blog/implementing-soft-delete-in-django-an-intuitive-guide
- https://python.plainenglish.io/implementing-soft-delete-in-django-and-drf-application-7bef6b760f97
- https://www.techinterview.org/post/3233473308/lld-soft-delete-hard-delete/
- https://pypi.org/project/django-soft-delete/