-
Notifications
You must be signed in to change notification settings - Fork 3
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
is this library suitable for this kind of bulk updates? #3
Comments
Sure. For this case, you could use any combination of:
All of them would like: from model_values import F
Book.objects.filter(F.field1 != None, F.field2 == None)['field2'] = F.field1 |
Thanks for response
Is this possible instead? from model_values import F
Book.objects.filter(field1__isnull=False,field2__isnull=True)['field2'] = F.field1 what abt custom save logicAnother follow up question I have is: so custom logic in the save method of Book model is NOT triggered when i update using the model-values way yes? For e.g. I use model-utils to have Will those be triggered in my bulk_update via model-values? |
from model_values import F
Book.objects.filter(field1__isnull=False,field2__isnull=True)['field2'] = F.field1 Yes, that works.
Correct, but that's true of Django's update method:
not just in model-values.
No, but that also is consistent with Django's DateField.auto_now:
The way to do implement a from django.utils import timezone
.update(modified=timezone.now(), **...) That updates .change({'modified': timezone.now()}, **...) |
abt Django update
So can I say that ultimately,
Oh... that's very very sweet! question abt affected recordsusing the same If I run the SQL query on postgres via a UI client like TablePlus, there's feedback on the number of records matched and affected. I know that the regular Django and i quote
|
model-values' |
Thanks @coady ! Sorry I just saw this |
Hi there,
i read your bad, ugly, good examples in the docs. I am still unsure if your library solves my use case well.
my version would be
in english
find all books which is not null at field1 and is null at field2 and then update individual book such that individual book field2 equals to individual book field1.
in sql
in django orm bad
in django-model-values
??
Is this usecase even suitable?
Thank you
The text was updated successfully, but these errors were encountered: