我的django模型包含字段:city
,country_name
和country_code
。
我有一个字典,它有超过8个键值对;我只想使用3并写入数据库。
但我收到错误
ModelBase object got multiple values for keyword argument 'country_code'
我的代码:
dicty = {
'city': u'Mountain View', 'continent_code': u'NA', 'region': u'CA',
'charset': 0, 'area_code': 650, 'longitude': -122.05740356445312,
'country_code3': u'USA', 'latitude': 37.4192008972168, 'postal_code': u'94043',
'dma_code': 807, 'country_code': u'US', 'country_name': u'United States'
}
m = Logger(city='city',country_name='country_name',country_code='country_code',**dicty)
m.save()
答案 0 :(得分:5)
您正在为country_code
传递两个参数:
m = Logger(city='city', country_name='country_name',
country_code='country_code', **dicty)
# ^ here ^ and in here
因此,您同时获得country_code = "country_code"
和 country_code = u"US"
。如果您只想从字典中传递三个值,请执行以下操作:
m = Logger(city=dicty['city'], country_name=dicty['country_name'],
country_code=dicty['country_code'])