django_polymorphic icon indicating copy to clipboard operation
django_polymorphic copied to clipboard

Support instance_of with joins

Open jjelisiejew opened this issue 14 years ago • 0 comments

Suppose we have a model strucure: class ModelA(PolymorphicModel): b = ForeignKey('ModelB')

class ModelB(PolymorphicModel): pass

class ModelC(ModelB): pass

The query ModelB.objects.filter(instance_of=ModelC) expands to ModelB.objects.filter(polymorphic_ctype=ContentType.objects.get_for_model(ModelC))

But the query ModelA.objects.filter(b__instance_of=ModelC) fails with error "FieldError: Cannot resolve keyword 'instance_of' into field".

The expanded query: ModelA.objects.filter(b__polymorphic_ctype=ContentType.objects.get_for_model(ModelC)) works as expected, so it only a translation issue. I think it would be great to have this fixed. Thank you very much for this project, Joachim Jelisiejew

P. S. I am working with django 1.3.0 and newest version of django_polymorphic .

jjelisiejew avatar Aug 29 '11 15:08 jjelisiejew