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

Add optimized update_or_create Manager method #1324

Open
tim-schilling opened this issue May 2, 2024 · 0 comments
Open

Add optimized update_or_create Manager method #1324

tim-schilling opened this issue May 2, 2024 · 0 comments

Comments

@tim-schilling
Copy link
Contributor

Problem Statement
Model.objects.update_or_create will always result in a .save() call which means there will always be a new historical record created regardless if there were any changes.

Describe the solution you'd like
There could be a method similar to update_or_create that inspects the updating defaults for changes from the fetched instance. Only if there are actual changes would it make a call to .save().

I have a proposed method here: https://gist.github.com/tim-schilling/b04846542927f6e6be777612e4b89d57

Describe alternatives you've considered
None

Additional context
This would not be compatible with someone who is using DateTimeField(auto_now=True) as a heartbeat field.

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

No branches or pull requests

1 participant