Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support see changes for columns added during __init__ #73

Open
Irostovsky opened this issue Mar 23, 2021 · 1 comment
Open

Support see changes for columns added during __init__ #73

Irostovsky opened this issue Mar 23, 2021 · 1 comment

Comments

@Irostovsky
Copy link

Irostovsky commented Mar 23, 2021

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?

@rsinger86
Copy link
Owner

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants