【发布时间】:2012-06-06 14:23:50
【问题描述】:
class A(models.Model):
pass
class B(models.Model):
a = models.ForeignKey(A)
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
如何获取A-instance,通过其参数与一些B-instance链接。 我尝试这样做:
instances = { '1':10, '2':20, '3':30 }
for ct, id in instances.items():
qset |= Q(content_type=int(ct), object_id=int(id))
a = A.objects.all().select_related().filter(qset)
没有错误:«Cannot resolve keyword 'object_id' into field.» 我可以通过链接 B 得到什么?
谢谢!
[PS] 现在这个工作,但不是它应该的:
a_all = A.objects.all()
for a in a_all:
print a.a_set.filter(qset)
【问题讨论】:
标签: django django-select-related django-q