Django & Soft Deletion: Implementation Architecture

Definitions

  • SOFT DELETE - Does not delete an object from the database, but seems to do so
  • HARD DELETE - completely removes an object from the database

Question

What is the best way to implement soft deletion in a code base (specifically, a Django project)?

The simplest method, I think, would be to simply add:

is_deleted = models.BooleanField(default=False)

for a superclass that implements softDeleteObjectand then overrides delete()to set the appropriate flags for the objects in question. Linked objects also need to inherit from the same superclass.

An alternative would be to remove the source text instead and have what constitutes the Archive object, which is the deleted objects.

Analysis

, -, , - , User , , .

pre_delete, . ( delete()), , .

, ?

+5
1

active/deleted/status , , ? django-reversion, , , ;)

+1

All Articles