gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
786 stars 139 forks source link

Track changes made to ORM fields since fetch/save #159

Closed mesozoic closed 1 year ago

mesozoic commented 2 years ago

I have some use cases that require me to keep track of which fields I've changed. This branch adds a new public property to each model, Model.changes, which will record any changes made to the model's fields since the last time it was fetched or persisted. The implementation relies on each field telling the model instance about a change as it happens.

This could probably be a lot more robust and featureful, but I didn't want to overcomplicate things before writing a few tests for the basics and opening a branch.

fbertoia commented 2 years ago

Is this something like this you are looking for ? https://docs.djangoproject.com/en/4.1/ref/models/instances/#django.db.models.Model.refresh_from_db

I suggest the same keyword then. 😀

mesozoic commented 1 year ago

Is this something like this you are looking for ? https://docs.djangoproject.com/en/4.1/ref/models/instances/#django.db.models.Model.refresh_from_db

Not exactly. I'm more thinking of "dirty fields", similar to the django-dirtyfields plugin. I could've mimicked that API more closely but wanted to get some feedback on the idea before building out any more functionality.

mesozoic commented 1 year ago

This is my own branch and it's kinda outdated. I'll close for now and we can come back to this later.