Django model soft delete pattern

2959
0

Soft deletes mark records as deleted without removing them from the database. I add a deleted_at field and override the delete() method. A custom manager excludes soft-deleted records by default. I provide a hard_delete() method for permanent removal. This enables undo functionality and maintains referential integrity. For auditing, soft deletes preserve history. I index deleted_at for query performance. Periodic cleanup jobs can hard-delete old soft-deleted records. This pattern is essential for user-facing delete operations.