django-polymorphic


Namedjango-polymorphic JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/django-polymorphic/django-polymorphic
SummarySeamless polymorphic inheritance for Django models
upload_time2021-11-18 11:55:40
maintainerChristopher Glass
docs_urlNone
authorBert Constantin
requires_python
license
keywords django polymorphic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            .. image::  https://travis-ci.org/django-polymorphic/django-polymorphic.svg?branch=master
    :target: http://travis-ci.org/django-polymorphic/django-polymorphic
.. image:: https://img.shields.io/pypi/v/django-polymorphic.svg
    :target: https://pypi.python.org/pypi/django-polymorphic/
.. image:: https://img.shields.io/codecov/c/github/django-polymorphic/django-polymorphic/master.svg
    :target: https://codecov.io/github/django-polymorphic/django-polymorphic?branch=master
.. image:: https://readthedocs.org/projects/django-polymorphic/badge/?version=stable
    :target: https://django-polymorphic.readthedocs.io/en/stable/

Polymorphic Models for Django
=============================

Django-polymorphic simplifies using inherited models in Django projects.
When a query is made at the base model, the inherited model classes are returned.

When we store models that inherit from a ``Project`` model...

.. code-block:: python

    >>> Project.objects.create(topic="Department Party")
    >>> ArtProject.objects.create(topic="Painting with Tim", artist="T. Turner")
    >>> ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")

...and want to retrieve all our projects, the subclassed models are returned!

.. code-block:: python

    >>> Project.objects.all()
    [ <Project:         id 1, topic "Department Party">,
      <ArtProject:      id 2, topic "Painting with Tim", artist "T. Turner">,
      <ResearchProject: id 3, topic "Swallow Aerodynamics", supervisor "Dr. Winter"> ]

Using vanilla Django, we get the base class objects, which is rarely what we wanted:

.. code-block:: python

    >>> Project.objects.all()
    [ <Project: id 1, topic "Department Party">,
      <Project: id 2, topic "Painting with Tim">,
      <Project: id 3, topic "Swallow Aerodynamics"> ]

This also works when the polymorphic model is accessed via
ForeignKeys, ManyToManyFields or OneToOneFields.

Features
--------

* Full admin integration.
* ORM integration:

  * support for ForeignKey, ManyToManyField, OneToOneField descriptors.
  * Filtering/ordering of inherited models (``ArtProject___artist``).
  * Filtering model types: ``instance_of(...)`` and ``not_instance_of(...)``
  * Combining querysets of different models (``qs3 = qs1 | qs2``)
  * Support for custom user-defined managers.
* Uses the minumum amount of queries needed to fetch the inherited models.
* Disabling polymorphic behavior when needed.

While *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!

The current release of *django-polymorphic* supports Django 2.1, 2.2, 3.0, 3.1
and Python 3.5+ is supported.
For older Django versions, install *django-polymorphic==1.3*.

For more information, see the `documentation at Read the Docs <https://django-polymorphic.readthedocs.io/>`_.

Installation
------------

Install using ``pip``\ ...

.. code:: bash

    $ pip install django-polymorphic

License
=======

Django-polymorphic uses the same license as Django (BSD-like).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/django-polymorphic/django-polymorphic",
    "name": "django-polymorphic",
    "maintainer": "Christopher Glass",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "tribaal@ubuntu.com",
    "keywords": "django,polymorphic",
    "author": "Bert Constantin",
    "author_email": "bert.constantin@gmx.de",
    "download_url": "https://files.pythonhosted.org/packages/4e/06/f43d3d7e690a6bd90c0e300d824f5aad0e9840cfd8d5bb164fd06ef6bcfc/django-polymorphic-3.1.0.tar.gz",
    "platform": "",
    "description": ".. image::  https://travis-ci.org/django-polymorphic/django-polymorphic.svg?branch=master\n    :target: http://travis-ci.org/django-polymorphic/django-polymorphic\n.. image:: https://img.shields.io/pypi/v/django-polymorphic.svg\n    :target: https://pypi.python.org/pypi/django-polymorphic/\n.. image:: https://img.shields.io/codecov/c/github/django-polymorphic/django-polymorphic/master.svg\n    :target: https://codecov.io/github/django-polymorphic/django-polymorphic?branch=master\n.. image:: https://readthedocs.org/projects/django-polymorphic/badge/?version=stable\n    :target: https://django-polymorphic.readthedocs.io/en/stable/\n\nPolymorphic Models for Django\n=============================\n\nDjango-polymorphic simplifies using inherited models in Django projects.\nWhen 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.. code-block:: python\n\n    >>> Project.objects.create(topic=\"Department Party\")\n    >>> ArtProject.objects.create(topic=\"Painting with Tim\", artist=\"T. Turner\")\n    >>> ResearchProject.objects.create(topic=\"Swallow Aerodynamics\", supervisor=\"Dr. Winter\")\n\n...and want to retrieve all our projects, the subclassed models are returned!\n\n.. code-block:: python\n\n    >>> Project.objects.all()\n    [ <Project:         id 1, topic \"Department Party\">,\n      <ArtProject:      id 2, topic \"Painting with Tim\", artist \"T. Turner\">,\n      <ResearchProject: id 3, topic \"Swallow Aerodynamics\", supervisor \"Dr. Winter\"> ]\n\nUsing vanilla Django, we get the base class objects, which is rarely what we wanted:\n\n.. code-block:: python\n\n    >>> Project.objects.all()\n    [ <Project: id 1, topic \"Department Party\">,\n      <Project: id 2, topic \"Painting with Tim\">,\n      <Project: id 3, topic \"Swallow Aerodynamics\"> ]\n\nThis also works when the polymorphic model is accessed via\nForeignKeys, ManyToManyFields or OneToOneFields.\n\nFeatures\n--------\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 minumum amount of queries needed to fetch the inherited models.\n* Disabling polymorphic behavior when needed.\n\nWhile *django-polymorphic* makes subclassed models easy to use in Django,\nwe still encourage to use them with caution. Each subclassed model will require\nDjango to perform an ``INNER JOIN`` to fetch the model fields from the database.\nWhile taking this in mind, there are valid reasons for using subclassed models.\nThat's what this library is designed for!\n\nThe current release of *django-polymorphic* supports Django 2.1, 2.2, 3.0, 3.1\nand Python 3.5+ is supported.\nFor older Django versions, install *django-polymorphic==1.3*.\n\nFor more information, see the `documentation at Read the Docs <https://django-polymorphic.readthedocs.io/>`_.\n\nInstallation\n------------\n\nInstall using ``pip``\\ ...\n\n.. code:: bash\n\n    $ pip install django-polymorphic\n\nLicense\n=======\n\nDjango-polymorphic uses the same license as Django (BSD-like).\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Seamless polymorphic inheritance for Django models",
    "version": "3.1.0",
    "project_urls": {
        "Download": "https://github.com/django-polymorphic/django-polymorphic/tarball/master",
        "Homepage": "https://github.com/django-polymorphic/django-polymorphic"
    },
    "split_keywords": [
        "django",
        "polymorphic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86f7e87f43be83760793fc3baeed499839b1580fda863dd30441c1661ff2fd96",
                "md5": "811441f5ade32f9bc0139cd52113758a",
                "sha256": "08bc4f4f4a773a19b2deced5a56deddd1ef56ebd15207bf4052e2901c25ef57e"
            },
            "downloads": -1,
            "filename": "django_polymorphic-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "811441f5ade32f9bc0139cd52113758a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 63415,
            "upload_time": "2021-11-18T11:55:38",
            "upload_time_iso_8601": "2021-11-18T11:55:38.663786Z",
            "url": "https://files.pythonhosted.org/packages/86/f7/e87f43be83760793fc3baeed499839b1580fda863dd30441c1661ff2fd96/django_polymorphic-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e06f43d3d7e690a6bd90c0e300d824f5aad0e9840cfd8d5bb164fd06ef6bcfc",
                "md5": "28b2de5b91816e842b7a533496fd3854",
                "sha256": "d6955b5308bf6e41dcb22ba7c96f00b51dfa497a8a5ab1e9c06c7951bf417bf8"
            },
            "downloads": -1,
            "filename": "django-polymorphic-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "28b2de5b91816e842b7a533496fd3854",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 50106,
            "upload_time": "2021-11-18T11:55:40",
            "upload_time_iso_8601": "2021-11-18T11:55:40.825253Z",
            "url": "https://files.pythonhosted.org/packages/4e/06/f43d3d7e690a6bd90c0e300d824f5aad0e9840cfd8d5bb164fd06ef6bcfc/django-polymorphic-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-11-18 11:55:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "django-polymorphic",
    "github_project": "django-polymorphic",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "tox": true,
    "lcname": "django-polymorphic"
}
        
Elapsed time: 0.13278s