Django library that returns real subclass instances when you query a shared base model, instead of only the base type. It extends standard model inheritance with admin and ORM integration.
Overview
django-polymorphic builds on Django’s model inheritance so queries on a base model can return the actual inherited classes. Storing several subclasses under one parent and listing them through the parent manager yields subclass objects rather than plain base rows, which standard Django does not do by default.
The same behavior applies when polymorphic models are reached through foreign keys, many-to-many fields, or one-to-one relations. You can filter or order on fields defined on subclasses, filter types with instanceof and notinstanceof helpers, and union querysets from different models. Custom managers are supported, and polymorphic fetching is designed to use few queries.
Admin integration is included, with support for proxy models, formsets, and patterns such as inline models and filtering child types. You can disable polymorphic behavior when needed. Documentation warns that each subclass adds INNER JOIN cost and recommends using inheritance only when it fits your data model.
Integrations mentioned in docs include django-guardian, django-extra-views, django-reversion, and model-bakery, plus guidance for migrations, fixtures, and working with third-party models without modifying them.
Key features
- Subclass instances from base queries
- Django admin integration
- Polymorphic access via model relations
- instanceof and notinstanceof filters
- Combine querysets across models
- Custom manager support
- Optional non-polymorphic queries
- Proxy model support
Use cases
- Shared Project base with typed subclasses
- Polymorphic relations in Django apps
- Admin for multi-type model trees
- Filter lists by concrete model type
- Downcast and upcast between parent and child