I have a model:
class Object(Object1):
name = models.CharField(max_length=255, blank=True)
description = models.TextField(blank=True)
date_updated = models.DateTimeField(blank=True, null=True)
I want to track if there is anything inserted into the date_updated field, then create another object in another model, without overriding the save method.
For example:
if date_updated:
MyModel.objects.create(type="D", user=request.user)
Although I have tried this, but still no success.
You can use tracker field from django-model-utils.
Add a tracker to the model:
class Object(Model):
name = models.CharField(max_length=255, blank=True)
description = models.TextField(blank=True)
date_updated = models.DateTimeField(blank=True, null=True)
tracker = FieldTracker()
You can check in save() or in other places where you usually update the model:
if object.tracker.has_changed('date_updated'):
create_new_object(data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With