{ "info": { "author": "Denis Orehovsky", "author_email": "denis.orehovsky@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Framework :: Django :: 1.11", "Framework :: Django :: 2.0", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "\n.. image:: https://travis-ci.org/apirobot/django-rest-polymorphic.svg?branch=master\n :target: https://travis-ci.org/apirobot/django-rest-polymorphic\n\n.. image:: https://codecov.io/gh/apirobot/django-rest-polymorphic/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/apirobot/django-rest-polymorphic\n\n.. image:: https://badge.fury.io/py/django-rest-polymorphic.svg\n :target: https://badge.fury.io/py/django-rest-polymorphic\n\n\n=======================\nDjango REST Polymorphic\n=======================\n\nPolymorphic serializers for Django REST Framework.\n\n\nOverview\n--------\n\n``django-rest-polymorphic`` allows you to easily define serializers for your inherited models that you have created using ``django-polymorphic`` library.\n\n\nInstallation\n------------\n\nInstall using ``pip``:\n\n.. code-block:: bash\n\n $ pip install django-rest-polymorphic\n\n\nUsage\n-----\n\nDefine your polymorphic models:\n\n.. code-block:: python\n\n # models.py\n from django.db import models\n from polymorphic.models import PolymorphicModel\n\n\n class Project(PolymorphicModel):\n topic = models.CharField(max_length=30)\n\n\n class ArtProject(Project):\n artist = models.CharField(max_length=30)\n\n\n class ResearchProject(Project):\n supervisor = models.CharField(max_length=30)\n\nDefine serializers for each polymorphic model the way you did it when you used ``django-rest-framework``:\n\n.. code-block:: python\n\n # serializers.py\n from rest_framework import serializers\n from .models import Project, ArtProject, ResearchProject\n\n\n class ProjectSerializer(serializers.ModelSerializer):\n class Meta:\n model = Project\n fields = ('topic', )\n\n\n class ArtProjectSerializer(serializers.HyperlinkedModelSerializer):\n class Meta:\n model = ArtProject\n fields = ('topic', 'artist', 'url')\n extra_kwargs = {\n 'url': {'view_name': 'project-detail', 'lookup_field': 'pk'},\n }\n\n\n class ResearchProjectSerializer(serializers.ModelSerializer):\n class Meta:\n model = ResearchProject\n fields = ('topic', 'supervisor')\n\nNote that if you extend ``HyperlinkedModelSerializer`` instead of ``ModelSerializer`` you need to define ``extra_kwargs`` to direct the URL to the appropriate view for your polymorphic serializer.\n\nThen you have to create a polymorphic serializer that serves as a mapper between models and serializers which you have defined above:\n\n.. code-block:: python\n\n # serializers.py\n from rest_polymorphic.serializers import PolymorphicSerializer\n\n\n class ProjectPolymorphicSerializer(PolymorphicSerializer):\n model_serializer_mapping = {\n Project: ProjectSerializer,\n ArtProject: ArtProjectSerializer,\n ResearchProject: ResearchProjectSerializer\n }\n\nCreate viewset with serializer_class equals to your polymorphic serializer:\n\n.. code-block:: python\n\n # views.py\n from rest_framework import viewsets\n from .models import Project\n from .serializers import ProjectPolymorphicSerializer\n\n\n class ProjectViewSet(viewsets.ModelViewSet):\n queryset = Project.objects.all()\n serializer_class = ProjectPolymorphicSerializer\n\nTest it:\n\n.. code-block:: bash\n\n $ http GET \"http://localhost:8000/projects/\"\n\n.. code-block:: http\n\n HTTP/1.0 200 OK\n Content-Length: 227\n Content-Type: application/json\n\n [\n {\n \"resourcetype\": \"Project\",\n \"topic\": \"John's gathering\"\n },\n {\n \"artist\": \"T. Turner\",\n \"resourcetype\": \"ArtProject\",\n \"topic\": \"Sculpting with Tim\",\n \"url\": \"http://localhost:8000/projects/2/\"\n },\n {\n \"resourcetype\": \"ResearchProject\",\n \"supervisor\": \"Dr. Winter\",\n \"topic\": \"Swallow Aerodynamics\"\n }\n ]\n\n.. code-block:: bash\n\n $ http POST \"http://localhost:8000/projects/\" resourcetype=\"ArtProject\" topic=\"Guernica\" artist=\"Picasso\"\n\n.. code-block:: http\n\n HTTP/1.0 201 Created\n Content-Length: 67\n Content-Type: application/json\n\n {\n \"artist\": \"Picasso\",\n \"resourcetype\": \"ArtProject\",\n \"topic\": \"Guernica\",\n \"url\": \"http://localhost:8000/projects/4/\"\n }\n\n\nCustomize resource type\n-----------------------\n\nAs you can see from the example above, in order to specify the type of your polymorphic model, you need to send a request with resource type field. The value of resource type should be the name of the model.\n\nIf you want to change the resource type field name from ``resourcetype`` to something else, you should override ``resource_type_field_name`` attribute:\n\n.. code-block:: python\n\n class ProjectPolymorphicSerializer(PolymorphicSerializer):\n resource_type_field_name = 'projecttype'\n ...\n\nIf you want to change the behavior of resource type, you should override ``to_resource_type`` method:\n\n.. code-block:: python\n\n class ProjectPolymorphicSerializer(PolymorphicSerializer):\n ...\n\n def to_resource_type(self, model_or_instance):\n return model_or_instance._meta.object_name.lower()\n\nNow, the request for creating new object will look like this:\n\n.. code-block:: bash\n\n $ http POST \"http://localhost:8000/projects/\" projecttype=\"artproject\" topic=\"Guernica\" artist=\"Picasso\"\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/apirobot/django-rest-polymorphic", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "django-rest-polymorphic", "package_url": "https://pypi.org/project/django-rest-polymorphic/", "platform": "", "project_url": "https://pypi.org/project/django-rest-polymorphic/", "project_urls": { "Homepage": "https://github.com/apirobot/django-rest-polymorphic" }, "release_url": "https://pypi.org/project/django-rest-polymorphic/0.1.8/", "requires_dist": [ "django", "djangorestframework", "django-polymorphic", "six" ], "requires_python": "", "summary": "Polymorphic serializers for Django REST Framework.", "version": "0.1.8" }, "last_serial": 4363748, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f70335ac16308c6d2ddda4aa0a036ed7", "sha256": "696a0bccec98d7d1ca820acadb92f786473cf332fb807b7a3fe834b9dcc4c1c1" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f70335ac16308c6d2ddda4aa0a036ed7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6000, "upload_time": "2017-12-07T13:57:53", "url": "https://files.pythonhosted.org/packages/3b/9a/228dfcac995ddbacbb8fd3d616fc4281144bd981e4cc83e388fb0cc6e714/django_rest_polymorphic-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ab303830164bcafc17d2a275b197aa95", "sha256": "1c2c536edefeabf07922ff9ae7f426acaa7d8137038f2137a4651abf488ab4d3" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ab303830164bcafc17d2a275b197aa95", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5111, "upload_time": "2017-12-07T13:57:55", "url": "https://files.pythonhosted.org/packages/90/67/d9affc4f55790920b030c7783a474dce9271dbca77c4dc2e60aead6535e0/django-rest-polymorphic-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "dbda73df3d519e059fed05d5fce4755c", "sha256": "aeccafa475d2aa9872504acb5e3d190bd30cbcb98c4fb2acce45df18aec7773a" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dbda73df3d519e059fed05d5fce4755c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6211, "upload_time": "2017-12-08T13:05:42", "url": "https://files.pythonhosted.org/packages/a8/32/8f65188906eab8a7f8ef12a676514e0e54f0ba7c5bb7eccc44bd42f47cac/django_rest_polymorphic-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b3043b0d06e23a57e6801b00b919a1c1", "sha256": "6406826ef9bf469dea630df0768cb3a41e7b075708cda0e9af0b81a3c11d09cc" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b3043b0d06e23a57e6801b00b919a1c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5262, "upload_time": "2017-12-08T13:05:44", "url": "https://files.pythonhosted.org/packages/3f/02/c4dfb220cf093c2344492ccc98398406244ab0b8fac5feb6fc40951ca84a/django-rest-polymorphic-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "a23a4e0177b42093c956346b46bde135", "sha256": "aab4b3379ca89efa4f9a93b920430e4037e8c1b548fdcb13f03e3f455a39a895" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a23a4e0177b42093c956346b46bde135", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6198, "upload_time": "2018-01-30T15:43:52", "url": "https://files.pythonhosted.org/packages/6a/98/c55c823699ff204c2b052664d134e751d31c8980be2493653b2b08407b44/django_rest_polymorphic-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cdd1d7efe05441dba73f0ed3ce0cdaae", "sha256": "53937742712ea8846d5a3268a263e5d78cdf000f5401fefedf95bf74c4f12727" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.2.tar.gz", "has_sig": false, "md5_digest": "cdd1d7efe05441dba73f0ed3ce0cdaae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5239, "upload_time": "2018-01-30T15:43:54", "url": "https://files.pythonhosted.org/packages/12/76/e87e63ca882c6ea4d702a78fb688efd60e71c74d4b3e1112771c5e5e7db1/django-rest-polymorphic-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "27f227d40c4dd0e144172502520f4b8e", "sha256": "5fea20d8b9dd7c6cdd352e70d6cac602cbb33d986436577500c62ed4c7362b6d" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "27f227d40c4dd0e144172502520f4b8e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6233, "upload_time": "2018-02-09T14:01:37", "url": "https://files.pythonhosted.org/packages/c8/ca/78a8d9ddc205f35e930b6ba7d50a5e3ed5d631858080d975e85a0d8c4d17/django_rest_polymorphic-0.1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b86897b653683cd4ddf4e2cd92cd4db6", "sha256": "68e64f0f64fcea9a50dc57268462c5680e15641e4c70a0358cf5b74cb6da59c1" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.3.tar.gz", "has_sig": false, "md5_digest": "b86897b653683cd4ddf4e2cd92cd4db6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5293, "upload_time": "2018-02-09T14:01:39", "url": "https://files.pythonhosted.org/packages/ea/1f/0b08fa154f2bfcc9be5564591eecbd5508646a51c5e22e82ee3151b9a84c/django-rest-polymorphic-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "b1355a8cc66424bfb1c9611d6a959ec8", "sha256": "84b86fcfa2aacb2c599f467282b7ed7a4fe7a614f61aff2348a7ccbee62e3bb8" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b1355a8cc66424bfb1c9611d6a959ec8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6220, "upload_time": "2018-02-10T12:00:43", "url": "https://files.pythonhosted.org/packages/82/69/9228c14cdb8441332864065b3d0484461e7c74d1b4faa941b9712c207003/django_rest_polymorphic-0.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "981f588e5532a69d1cd4f1b3b2336a65", "sha256": "107eb49fcbc04324ab5452e100faef956ed716d56e3946f3b754426561d62343" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.4.tar.gz", "has_sig": false, "md5_digest": "981f588e5532a69d1cd4f1b3b2336a65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5296, "upload_time": "2018-02-10T12:00:44", "url": "https://files.pythonhosted.org/packages/e2/45/d104c60aecdd0e270794a3d68b4536aa13e935d7b472cc3d6a43a5b75b6a/django-rest-polymorphic-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "ed7d9aa8a9733d161af97ede9fc8d549", "sha256": "1e7b3b1a2bd797c0fa0255f9b8a865e9be87f5a21f35737cae240810d92d80fb" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ed7d9aa8a9733d161af97ede9fc8d549", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6615, "upload_time": "2018-03-29T04:33:22", "url": "https://files.pythonhosted.org/packages/7b/d7/2a9fbe287f7bb5d4e2ef340130ecdd545c61e789338728d7fc4882e88be6/django_rest_polymorphic-0.1.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "923b5e4370d72d6de3cf9be7d9b0f756", "sha256": "cdbfa47c6e0020cef41fca6160e598effae42eb968b07df9cf9d4383aac1d849" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.5.tar.gz", "has_sig": false, "md5_digest": "923b5e4370d72d6de3cf9be7d9b0f756", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5620, "upload_time": "2018-03-29T04:33:23", "url": "https://files.pythonhosted.org/packages/48/87/6e2668feaa0234a4751b4005e819a8ca30956b58db9c1228aa5a57b10ee2/django-rest-polymorphic-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "743e6c4b5c274ff431b7c6acb89d6760", "sha256": "206a9e81d79a0cd31e4ecc655a00b629e0b8d964a8f15c4e241a509a3088e022" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "743e6c4b5c274ff431b7c6acb89d6760", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7229, "upload_time": "2018-06-03T09:05:29", "url": "https://files.pythonhosted.org/packages/d3/48/2ff46bb96bade3324d78de2d4013d24cdcad818f8a1781036fa1ae9a2822/django_rest_polymorphic-0.1.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aff5e0f04c24d17faf0ce1f7fe06f056", "sha256": "3976f04bc10c497886db925583fcdd34ed51dcb1fb3757d0f78d2574dfb3d48a" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.6.tar.gz", "has_sig": false, "md5_digest": "aff5e0f04c24d17faf0ce1f7fe06f056", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5959, "upload_time": "2018-06-03T09:05:31", "url": "https://files.pythonhosted.org/packages/54/c9/68b701e2acd53782d6f68acc520d3e66d747ba864b7edf061a6798653597/django-rest-polymorphic-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "38cb317a965c7d9da6cb756ee350b7d0", "sha256": "6123352ebee7ec3bdba3a18c05054be8e6c4e26cfad96b4fc536bc43215a2ca2" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "38cb317a965c7d9da6cb756ee350b7d0", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7238, "upload_time": "2018-06-06T13:19:25", "url": "https://files.pythonhosted.org/packages/76/bf/fe0cde8e4570cc295c691f0a425531aaccf9d6aa27bd12881b81caf319fb/django_rest_polymorphic-0.1.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "54c1339ca9df0c01f1cbf903d40b0291", "sha256": "a6da9082888a4518a536a73a016552f13effce190065ad5ad88839d554ec7ca1" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.7.tar.gz", "has_sig": false, "md5_digest": "54c1339ca9df0c01f1cbf903d40b0291", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5967, "upload_time": "2018-06-06T13:19:26", "url": "https://files.pythonhosted.org/packages/38/4e/4104bb733e8f7cec2e33985c43a51e7e4090457d110c959455b02a5eeedc/django-rest-polymorphic-0.1.7.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "b3444aace536217d49dcc951c1aeec32", "sha256": "a29a0a7a0fd804e7a9b0b86025591aa4ab23d4c450dd2b7a088c5976ac9283a1" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b3444aace536217d49dcc951c1aeec32", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5886, "upload_time": "2018-10-11T10:18:52", "url": "https://files.pythonhosted.org/packages/0e/77/b2eef0c31c8c623ef73fcf6cd3c1c7f22d7ee9bbbb0c6ba36ca5a3c9f07a/django_rest_polymorphic-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ed285fb8d6e3a084caf092f00e60d30f", "sha256": "8a763ab0459b93724d186e101c3b92d0b1916305b6b221f65064c02ebc2267a8" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.8.tar.gz", "has_sig": false, "md5_digest": "ed285fb8d6e3a084caf092f00e60d30f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5983, "upload_time": "2018-10-11T10:18:54", "url": "https://files.pythonhosted.org/packages/d8/d9/60a36f52822614271f3d6fc849306963a00985f19eb95be6239cffcf03a3/django-rest-polymorphic-0.1.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b3444aace536217d49dcc951c1aeec32", "sha256": "a29a0a7a0fd804e7a9b0b86025591aa4ab23d4c450dd2b7a088c5976ac9283a1" }, "downloads": -1, "filename": "django_rest_polymorphic-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b3444aace536217d49dcc951c1aeec32", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5886, "upload_time": "2018-10-11T10:18:52", "url": "https://files.pythonhosted.org/packages/0e/77/b2eef0c31c8c623ef73fcf6cd3c1c7f22d7ee9bbbb0c6ba36ca5a3c9f07a/django_rest_polymorphic-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ed285fb8d6e3a084caf092f00e60d30f", "sha256": "8a763ab0459b93724d186e101c3b92d0b1916305b6b221f65064c02ebc2267a8" }, "downloads": -1, "filename": "django-rest-polymorphic-0.1.8.tar.gz", "has_sig": false, "md5_digest": "ed285fb8d6e3a084caf092f00e60d30f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5983, "upload_time": "2018-10-11T10:18:54", "url": "https://files.pythonhosted.org/packages/d8/d9/60a36f52822614271f3d6fc849306963a00985f19eb95be6239cffcf03a3/django-rest-polymorphic-0.1.8.tar.gz" } ] }