DB TABLE(null可以)
select * from TESTDB;
id | AAA | BBB | CCC |
======================
Django代码
new_dataset = TESTDB(BBB = 222)
new_dataset.save()
我想改变这样的代码......
target_field = 'BBB'
new_dataset = TESTDB( target_field = 222 )
new_dataset.save()
如何完成此代码?
答案 0 :(得分:2)
您可以使用Python的dict as keyword arguments feature:
target_field = 'BBB'
new_dataset = TESTDB(**{target_field: 222})
new_dataset.save()