I have a list which contains dicts. Something like:
[{'id': 0, 'price': 20}, {'id': 1, 'price': 10}] # a few thousands of elements
how can I update corresponding models without constructing the whole QuerySet?
As of django-2.2, you can use .bulk_update(…)
[Django-doc]:
data = [{'id': 0, 'price': 20}, {'id': 1, 'price': 10}]
Match.objects.bulk_update([Match(**kv) for kv in data], ['price'])
We here thus construct Match
objects that we then pass to the bulk_update
to construct an update query.