Django には次のモデル継承構造があります。
class Parent(models.Model):
# stuff
class A(Parent):
# stuff
class B(Parent):
# stuff
class C(Parent):
# stuff
and the list goes on.
次のようなオブジェクトをフィルタリングするために、django-model-utils の InheritanceManager を使用しています。
Parent.objects.filter(foo=bar).select_subclasses()
これは、すべてのサブクラスをフィルタリングする場合にうまく機能します。私がやりたいのは、A オブジェクトと B オブジェクトをフィルター処理することですが、C オブジェクトはフィルター処理しません。次のような単一のクエリでこれを行いたい
Parent.objects.filter(foo=bar, __class__.__name__=A, __class__.__name__=B).select_subclasses()
そのようなフィルタリング操作を行うことは可能ですか?可能であればどのようにしますか?