I have to put limit on the number of records to update in Django ORM Model object.
I have tried:
CustomObject.objects.filter(column_x='XXX').update(column_y='YYY')[:10]
but slicing is not allowed with update.
I don't want to fetch the id separately and using those ids for update as the number of records is very large ( 1 million to 80 million ).
Interested in the hitting the DB once.
Use nested querying:
nested_q = CustomObject.objects.filter(column_x='XXX')[:10]
CustomObject.objects.filter(pk__in=nested_q).update(column_y='YYY')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With