romgar / django-dirtyfields

Tracking dirty fields on a Django model
BSD 3-Clause "New" or "Revised" License
630 stars 111 forks source link

add full_save_on_add arg to save_dirty_fields to save new instances #200

Closed GeyseR closed 2 years ago

GeyseR commented 2 years ago

in one of our projects with have a pattern, when we have an instance of a model, but don't know was it save to the DB or not. After updating several its fields we want to use optimized save_dirty_fields method for existing models, but save the full model otherwise.

So in this PR I try to suggest a way for simplify the case by adding a new argument to the save_dirty_fields method

LincolnPuzey commented 2 years ago

Is there a problem with calling .save_dirty_fields() on an unsaved instance that doesn't exist in the DB? I would've expected that to work

GeyseR commented 2 years ago

yes, django raises the error when trying to pass update_fields for the unsaved model https://github.com/romgar/django-dirtyfields/pull/200/files#diff-d48931ca655ff96651d77e9dc164175fff4906a08cadc62fb59e80b39c01c264R76

coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.01%) to 99.265% when pulling 23cb1c0a2df1d5ee1534b49a662012d8fdbf6c15 on GeyseR:full_save_on_add into c320d5eccca82dddd50cfc8599cca51336e83bc8 on romgar:develop.

LincolnPuzey commented 2 years ago

Thanks for the quick response! can you fix the flake8 error? or I can

GeyseR commented 2 years ago

Thanks for the quick response! can you fix the flake8 error? or I can

fixed