django-lifecycle
django-lifecycle copied to clipboard
Support see changes for columns added during __init__
Hello, today I tried to move some our signals to the hooks and realised that if column was added into model init then it is shown as not changed. Ex:
class Reservation(DirtyFieldsMixin, LifecycleModelMixin, models.Model):
...
In [15]: r = Reservation(edit_comment='test')
In [16]: r.has_changed('edit_comment')
Out[16]: False
In [17]: r.get_dirty_fields(check_relationship=True, verbose=True).get('edit_comment')
Out[17]: {'saved': None, 'current': 'test'}
In [18]: r = Reservation()
In [19]: r.edit_comment = 'test'
In [20]: r.has_changed('edit_comment')
Out[20]: True
So, if column is changed AFTER init - it is shown as changed, if into init - not. Is it possible to cover this case too?
I'm not sure about this. If it's passed in init, then it's the initial value so it doesn't seem like it's really changed. There is no prior value.
What about adding new hookable moments for "before_init" and "after_init"? These could mirror the built-in pre_init and post_init signals: https://docs.djangoproject.com/en/3.2/ref/signals/