Closed bbyan closed 4 years ago
not sure I understand, you want to pass a dict
of a specific model attributes or a dict not even attached to a specific model?
The latter is not possible as Django ORM is inherently bound to a Model and this method uses ORM bulk_update
behind it which requires the batch update to happen on the same model/table.
if you just want to instantiate objects with different attributes you can use the typical **dict
syntax
using RandomData as example
d1 = {'uuid': 1, 'data': 'data for 1', 'optional_field': 1}
d2 = {'uuid': 1, 'data': 'data for 1', 'other_optional_field': 2}
items = [
RandomData(**d1),
RandomData(**d2),
]
It does however imply that (from this example) both optional_field
and other_optional_field
need to be part of the batch update_fields
.
Hello fopina, Thank you for writing this very useful module. But when using it, there was a problem that I couldn't solve.
for example: I have data of dict type
dicts = {a:'b',c:'d',e:'f'}
In your use case, I must do:items = [ data(a='b',c='e',e='f')]
But in my case , this dic is dynamic and I cannot write dead code.And there are quite a few KEYs in the actual dicts. I would like to ask if related functions will be supported next, or how can I deal with this problem.
thank you,