[Answered ]-Django filter sub-class models

2๐Ÿ‘

โœ…

(Update: This Answer on a previously asked question is better than what Iโ€™ve written below.)

This article explains why this is inefficient in Django โ€” basically, because it would require expensive joins across the tables for all the subclasses. (Iโ€™ve written an ORM that does polymorphism like that, and the queries get out of hand very quickly. The Django guys made the right decision here.)

The article describes a method for writing a MixIn to query each subclass individually. If you need that behavior across your app, consider implementing something like that.

If this is for a single view, you may be better off (quicker, and easier to understand) just writing your view to query each subclass and create a list of all the results.

๐Ÿ‘คMatt Miller

Leave a comment