Pass in a dict argument to objects.create

Is it feasible to pass in a dict as an argument to the objects.create method ?

soDict = {
    'customer': data['customer_id'],
    'name': data['name'],
so = ServiceOrder.objects.create(**soDict)

Instead of so = ServiceOrder.objects.create(**soDict) do something like

so = ServiceOrder(**soDict)

Also customer and name should be fields in your ServiceOrder model.

1 Like

This works. To be more pedantic, the code in the OP is not passing a dict. It’s unpacking the dictionary as key word arguments (kwargs) to the create method.