Filtering normal model based on related polymorphic model type? #731
Unanswered
niekvanderkooy
asked this question in
Q&A
Replies: 2 comments
-
|
I just realised I can do something like |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@niekvanderkooy Yes you could do this, as you suggest: NormalModel.objects.filter(polymorphic_model__in=PolymorphicA.objects.all())You could also query against the polymorphic_ctype directly: NormalModel.objects.filter(polymoprhic_model__polymorphic_ctype=ContentType.objects.get_for_model(PolymorphicModel)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm sorry if this has been asked before, or has been documented somewhere, but I can't seem to find a way to do the following...
Say we have a
NormalModel, which has a foreign key to aPolymorphicModelwith childrenPolymorphicAandPolymorphicB. Is there a way to queryNormalModel, based on the type of the polymorphic relation?I would imagine something like
NormalModel.objects.filter(Q(polymorphic_model___instance_of=PolymorphicA)), but sinceNormalModelhas a normal manager,___instance_ofdoes not work. I could maybe hack around it withNormalModel.objects.filter(polymorphic_model__polymorphic_ctype_id=X)where I predetermineX, but I don't think that's how I should be doing things.Beta Was this translation helpful? Give feedback.
All reactions