我是初学者,所以请对我放轻松一点。我正在编写一个脚本,这样当我决定删除数据库时,不必一直输入数据。我的整个剧本都很好,除了处理一对多的关系。它不会保存到数据库。有谁能告诉我我做错了什么,或者给我指出正确的方向吗?在
脚本:
try:
pmod.Instrument.objects.get(title='kjkjsdfsadfs')
except pmod.Instrument.DoesNotExist:
u = pmod.Instrument()
u.title = 'Bach 42 Trombone'
u.price = 550.00
u.soundDescription = 'Good'
u.functionalityDescription = 'Good'
u.damageDescription = 'Good'
u.accessoryDescription = 'Good'
u.customerName = 'Jake'
u.customerEmail = 'ks@gmail.com'
u.instrumentCategory = 1
print('Good2')
u.save()
print('Instrument1 saved')
型号:
^{pr2}$
u.instrumentCategory = 1
这不是Django中
models.ForeignKey
字段的工作方式。{{cd3>需要一个您可以尝试:
相关问题 更多 >
编程相关推荐