我正在尝试更新一堆对象的 id 以及引用这些对象的相关表。
class Test(models.Model):
id=models.IntegerField(primary_key=True)
class Question(models.Model):
id=models.AutoField(primary_key=True)
test=models.ForeignKey('Test',db_column='testId')
d={1:2,5:10}
for fr,to in d.items():
Test.objects.filter(id=fr).update(id=to)
Question.objects.filter(test_id=fr).update(test_id=to)
我努力了test_id
, test__id
and testId
但收到此错误消息:
django.db.models.fields.FieldDoesNotExist: Question has no field named 'test_id'
目前这可能吗?
编辑:我不想加载Test
每次 id 更改的对象。
在 Django 1.8 中实现
Usage:
Bar.objects.filter(pk=foo.id).update(a_id=bar.id)
Bar.objects.filter(pk=foo.id).update(a=bar.id)
See ticket https://code.djangoproject.com/ticket/21144 and commit https://github.com/django/django/commit/c21e86ab9e3e5ebd6d245d038cb0cb352cd84c3a.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)