My project has a lot of models.
Each model has a field is_active that is True when in production and False when it is completed or not used .
Is there any default magic solution for this with Django? I have about 40-60 models so ideally it should be one solution covers all.
I found this answer Archiving model data in Django that requires development effort for each model individually and this will create lot of models.
Any Magic Alternatives?
I would solve this problem with Abstract Model Inheritance.
This will allow you to write logic for one class and set of fields and it will apply to all child classes.
class IsActive(models.Model):
class Meta:
abstract = True
is_active = models.BooleanField(default=False)
def toggle_active(self):
self.is_active = !self.is_active
class Child(IsActive):
# This object now has `is_active` and `toggle_active` fields.