Reputation: 893
Here is the situation:
I have a Django model save() function like this:
obj = Model1(attr1=params['attr1'], attr2=params['attr2'], attr3=params['attr3'], …)
or this:
class MyClass():
pass
my = MyClass()
…...
obj = Model2(attr1=my.attr1, attr2=my.attr2, attr3=my.attr3...)
totally more than twenty attributes.
It's a really long and non-fiendly expression. Better way to do this? Thanks!
Upvotes: 1
Views: 48
Reputation: 3244
I prefer something like this
params = {
'param1': param1,
'param2': param2,
....
}
obj = Model1(**params)
Upvotes: 0