I'm implementing the first option discussed in "Marking for deletion in Django", that is, when an object is no longer active, I set a boolean to mark it as inactive.
The specific reason I'm using this method is that although the object is no longer in active use, it may still be referenced and displayed in various records and reporting outputs. I don't want Django's ripple delete to remove the old records.
How should I go about enforcing uniqueness of active objects?
Initially, I thought I should use unique_together
to enforce my constraints at a database level. This works fine until I delete an object, at which point adding a new active object with the same name violates the uniqueness requirement. I could simply reflag the object as active, but I actually want a new object.
I'm looking for something that lets me say something like "unique together when active = True". I could enforce this in the model creation code, but it seems like enforcing it at the database level is a better idea.
Any advice about which of these is the best approach? Any better suggestions?
Note: django-reversion is cool, but totally does not work for my application since I DO need to access "deleted" objects from time to time.