It is necessary to obtain an instance of class A, according to the instances of B. attached to it.
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')
I'm trying to do this:
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)
I get the error:
Cannot resolve keyword 'object_id' into field.
If so:
a_all = A.objects.all() for a in a_all: print a.a_set.filter(qset)
That works, but not quite as it should.
Actually, the question is: how can I get an instance of class A according to the exact occurrence of instances of class B attached to it?