{"id":13415850,"url":"https://github.com/jazzband/django-polymorphic","last_synced_at":"2026-02-06T02:18:07.467Z","repository":{"id":733692,"uuid":"1360247","full_name":"jazzband/django-polymorphic","owner":"jazzband","description":"Improved Django model inheritance with automatic downcasting","archived":false,"fork":false,"pushed_at":"2026-01-26T19:34:55.000Z","size":2347,"stargazers_count":1807,"open_issues_count":29,"forks_count":302,"subscribers_count":30,"default_branch":"master","last_synced_at":"2026-01-27T07:48:14.031Z","etag":null,"topics":["django","django-admin","django-formsets","django-orm","object-oriented","oop","polymorphism"],"latest_commit_sha":null,"homepage":"https://django-polymorphic.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jazzband.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://jazzband.co/donate"]}},"created_at":"2011-02-12T23:30:34.000Z","updated_at":"2026-01-26T20:58:39.000Z","dependencies_parsed_at":"2023-01-13T10:38:41.182Z","dependency_job_id":"f8876c78-c134-4524-b1fe-aace390b165c","html_url":"https://github.com/jazzband/django-polymorphic","commit_stats":{"total_commits":728,"total_committers":107,"mean_commits":6.803738317757009,"dds":"0.48901098901098905","last_synced_commit":"bd5faf0c829f87dc6fcc42c6bfbb689d665a5bf4"},"previous_names":["chrisglass/django_polymorphic","django-polymorphic/django-polymorphic"],"tags_count":69,"template":false,"template_full_name":null,"purl":"pkg:github/jazzband/django-polymorphic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdjango-polymorphic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdjango-polymorphic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdjango-polymorphic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdjango-polymorphic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jazzband","download_url":"https://codeload.github.com/jazzband/django-polymorphic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdjango-polymorphic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29145570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T01:13:33.096Z","status":"online","status_checked_at":"2026-02-06T02:00:08.092Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-admin","django-formsets","django-orm","object-oriented","oop","polymorphism"],"created_at":"2024-07-30T21:00:52.536Z","updated_at":"2026-02-06T02:18:07.417Z","avatar_url":"https://github.com/jazzband.png","language":"Python","readme":"# django-polymorphic\n\n[![License: BSD](https://img.shields.io/badge/License-BSD-blue.svg)](https://opensource.org/license/bsd-3-clause)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![PyPI version](https://badge.fury.io/py/django-polymorphic.svg)](https://pypi.python.org/pypi/django-polymorphic/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/django-polymorphic.svg)](https://pypi.python.org/pypi/django-polymorphic/)\n[![PyPI djversions](https://img.shields.io/pypi/djversions/django-polymorphic.svg)](https://pypi.org/project/django-polymorphic/)\n[![PyPI status](https://img.shields.io/pypi/status/django-polymorphic.svg)](https://pypi.python.org/pypi/django-polymorphic)\n[![Documentation Status](https://readthedocs.org/projects/django-polymorphic/badge/?version=latest)](http://django-polymorphic.readthedocs.io/?badge=latest/)\n[![Code Cov](https://img.shields.io/codecov/c/github/jazzband/django-polymorphic/master.svg)](https://codecov.io/github/jazzband/django-polymorphic?branch=master)\n[![Test Status](https://github.com/jazzband/django-polymorphic/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/jazzband/django-polymorphic/actions/workflows/test.yml?query=branch:master)\n[![Lint Status](https://github.com/jazzband/django-polymorphic/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/jazzband/django-polymorphic/actions/workflows/lint.yml?query=branch:master)\n[![Published on Django Packages](https://img.shields.io/badge/Published%20on-Django%20Packages-0c3c26)](https://djangopackages.org/packages/p/django-polymorphic/)\n[![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/)\n\n---------------------------------------------------------------------------------------------------\n\n[![Postgres](https://img.shields.io/badge/Postgres-12%2B-blue)](https://www.postgresql.org/)\n[![MySQL](https://img.shields.io/badge/MySQL-8.0%2B-blue)](https://www.mysql.com/)\n[![MariaDB](https://img.shields.io/badge/MariaDB-10.4%2B-blue)](https://mariadb.org/)\n[![SQLite](https://img.shields.io/badge/SQLite-3.8%2B-blue)](https://www.sqlite.org/)\n[![Oracle](https://img.shields.io/badge/Oracle-21c%2B-blue)](https://www.oracle.com/database/)\n\n---------------------------------------------------------------------------------------------------\n\n## Polymorphic Models for Django\n\n[django-polymorphic](https://pypi.python.org/pypi/django-polymorphic) simplifies using inherited models in [Django](https://djangoproject.com) projects. When a query is made at the base model, the inherited model classes are returned.\n\nWhen we store models that inherit from a ``Project`` model...\n\n```python\n\n    \u003e\u003e\u003e Project.objects.create(topic=\"Department Party\")\n    \u003e\u003e\u003e ArtProject.objects.create(topic=\"Painting with Tim\", artist=\"T. Turner\")\n    \u003e\u003e\u003e ResearchProject.objects.create(topic=\"Swallow Aerodynamics\", supervisor=\"Dr. Winter\")\n```\n\n...and want to retrieve all our projects, the subclassed models are returned!\n\n```python\n\n    \u003e\u003e\u003e Project.objects.all()\n    [ \u003cProject:         id 1, topic \"Department Party\"\u003e,\n      \u003cArtProject:      id 2, topic \"Painting with Tim\", artist \"T. Turner\"\u003e,\n      \u003cResearchProject: id 3, topic \"Swallow Aerodynamics\", supervisor \"Dr. Winter\"\u003e ]\n```\n\nUsing vanilla Django, we get the base class objects, which is rarely what we wanted:\n\n```python\n\n    \u003e\u003e\u003e Project.objects.all()\n    [ \u003cProject: id 1, topic \"Department Party\"\u003e,\n      \u003cProject: id 2, topic \"Painting with Tim\"\u003e,\n      \u003cProject: id 3, topic \"Swallow Aerodynamics\"\u003e ]\n```\n\nThis also works when the polymorphic model is accessed via\nForeignKeys, ManyToManyFields or OneToOneFields.\n\n### Features\n\n* Full admin integration.\n* ORM integration:\n\n  * support for ForeignKey, ManyToManyField, OneToOneField descriptors.\n  * Filtering/ordering of inherited models (``ArtProject___artist``).\n  * Filtering model types: ``instance_of(...)`` and ``not_instance_of(...)``\n  * Combining querysets of different models (``qs3 = qs1 | qs2``)\n  * Support for custom user-defined managers.\n* Uses the minimum amount of queries needed to fetch the inherited models.\n* Disabling polymorphic behavior when needed.\n\n\n**Note:** While [django-polymorphic](https://pypi.python.org/pypi/django-polymorphic) makes subclassed models easy to use in Django, we still encourage to use them with caution. Each subclassed model will require Django to perform an ``INNER JOIN`` to fetch the model fields from the database. While taking this in mind, there are valid reasons for using subclassed models. That's what this library is designed for!\n\nFor more information, see the [documentation at Read the Docs](https://django-polymorphic.readthedocs.io).\n\n### Installation\n\n```bash\n    $ pip install django-polymorphic\n```\n\n```python\nINSTALLED_APPS = [\n  ...\n  \"django.contrib.contenttypes\",  # we rely on the contenttypes framework\n  \"polymorphic\"\n]\n```\n\n## License\n\n[django-polymorphic](https://pypi.python.org/pypi/django-polymorphic) uses the same license as Django (BSD-like).\n","funding_links":["https://jazzband.co/donate"],"categories":["Third-Party Packages","Python","Django Utilities"],"sub_categories":["Models"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzband%2Fdjango-polymorphic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjazzband%2Fdjango-polymorphic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzband%2Fdjango-polymorphic/lists"}