drf-crud-proxy


Namedrf-crud-proxy JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/attevaltojarvi/drf-crud-proxy
SummarySeparate serializers for parsing requests and returning responses in DRF
upload_time2023-04-27 20:36:19
maintainer
docs_urlNone
authorattevaltojarvi
requires_python
licenseMIT
keywords django rest framework serializers rest api django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            DRF CRUD Proxy
==============

This package provides extended Django REST Framework generic views and viewsets that provide the possibility to specify
different serializers for reading the incoming request and presenting the response.

This is super handy in situations where you want to, for example, let the user send a ForeignKey attribute,
but present the related object alongside the response instead of only the database ID.

Requirements
------------

- Python 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11
- Django 3.2, 4.0, 4.1 and 4.2 (basically works with older versions as well, but they're EOL)
- Django REST Framework 3.8 or newer (probably works on any 3.x version)

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

.. code::

  pip install drf-crud-proxy

Usage
-----

Import the generic views and subclass your own views from them. Specify ``request_serializer_class`` and/or
``response_serializer_class`` to the view (both default to DRF's own ``serializer_class`` attribute).

.. code:: python

  # api/views.py

  from drf_crud_proxy import generics
  from app.models import MyModel
  from api.serializers import MyModelCreateSerializer, MyModelSerializer


  class MyModelListCreateView(generics.ProxiedListCreateAPIView):
      queryset = MyModel.objects.all()
      request_serializer_class = MyModelCreateSerializer
      response_serializer_class = MyModelSerializer

The incoming request is handled with ``MyModelCreateSerializer`` and the response with ``MyModelSerializer``.

If you want to customize the data on either situation, override ``get_request_data`` and/or ``get_response_data``
methods in the view.

The package also supports the so-called ``PUT-as-create`` behavior that was removed from DRF in its 3.0 release. Note that
the user has to have model permissions for the corresponding create behavior (``POST`` request).

**NOTE**: The ``PUT-as-create`` functionality doesn't have tests (yet).

License
-------

MIT

Inspiration
-----------

This functionality in DRF is something I've needed in numerous Django projects, so hopefully this will help someone else
too :)

This package has been built on top of the ideas presented by the great vintasoftware's ``drf-rw-serializers`` (https://github.com/vintasoftware/drf-rw-serializers) package. Thanks!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/attevaltojarvi/drf-crud-proxy",
    "name": "drf-crud-proxy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Django REST Framework,Serializers,REST,API,Django",
    "author": "attevaltojarvi",
    "author_email": "atte.valtojarvi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6d/79/cca76bdabd5b32e0606c089bb16ea3c3a205b27454635b9787fd2c75ac8f/drf-crud-proxy-0.4.0.tar.gz",
    "platform": null,
    "description": "DRF CRUD Proxy\n==============\n\nThis package provides extended Django REST Framework generic views and viewsets that provide the possibility to specify\ndifferent serializers for reading the incoming request and presenting the response.\n\nThis is super handy in situations where you want to, for example, let the user send a ForeignKey attribute,\nbut present the related object alongside the response instead of only the database ID.\n\nRequirements\n------------\n\n- Python 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11\n- Django 3.2, 4.0, 4.1 and 4.2 (basically works with older versions as well, but they're EOL)\n- Django REST Framework 3.8 or newer (probably works on any 3.x version)\n\nInstallation\n------------\n\n.. code::\n\n  pip install drf-crud-proxy\n\nUsage\n-----\n\nImport the generic views and subclass your own views from them. Specify ``request_serializer_class`` and/or\n``response_serializer_class`` to the view (both default to DRF's own ``serializer_class`` attribute).\n\n.. code:: python\n\n  # api/views.py\n\n  from drf_crud_proxy import generics\n  from app.models import MyModel\n  from api.serializers import MyModelCreateSerializer, MyModelSerializer\n\n\n  class MyModelListCreateView(generics.ProxiedListCreateAPIView):\n      queryset = MyModel.objects.all()\n      request_serializer_class = MyModelCreateSerializer\n      response_serializer_class = MyModelSerializer\n\nThe incoming request is handled with ``MyModelCreateSerializer`` and the response with ``MyModelSerializer``.\n\nIf you want to customize the data on either situation, override ``get_request_data`` and/or ``get_response_data``\nmethods in the view.\n\nThe package also supports the so-called ``PUT-as-create`` behavior that was removed from DRF in its 3.0 release. Note that\nthe user has to have model permissions for the corresponding create behavior (``POST`` request).\n\n**NOTE**: The ``PUT-as-create`` functionality doesn't have tests (yet).\n\nLicense\n-------\n\nMIT\n\nInspiration\n-----------\n\nThis functionality in DRF is something I've needed in numerous Django projects, so hopefully this will help someone else\ntoo :)\n\nThis package has been built on top of the ideas presented by the great vintasoftware's ``drf-rw-serializers`` (https://github.com/vintasoftware/drf-rw-serializers) package. Thanks!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Separate serializers for parsing requests and returning responses in DRF",
    "version": "0.4.0",
    "split_keywords": [
        "django rest framework",
        "serializers",
        "rest",
        "api",
        "django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0228089f183ee7657b9837855df3a64bc52d0def0a731f40cf89b94a2a7a7b19",
                "md5": "5cb5e49b35a30b5103b7ac381a2cad48",
                "sha256": "8b5887737df8dfbb3be073173142b53f06748da702aa6a07e354defe08a3da6d"
            },
            "downloads": -1,
            "filename": "drf_crud_proxy-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5cb5e49b35a30b5103b7ac381a2cad48",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6760,
            "upload_time": "2023-04-27T20:36:16",
            "upload_time_iso_8601": "2023-04-27T20:36:16.684435Z",
            "url": "https://files.pythonhosted.org/packages/02/28/089f183ee7657b9837855df3a64bc52d0def0a731f40cf89b94a2a7a7b19/drf_crud_proxy-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d79cca76bdabd5b32e0606c089bb16ea3c3a205b27454635b9787fd2c75ac8f",
                "md5": "701f49bd90aead3980b0a6a952c101a3",
                "sha256": "d95d877c14412cf9e07acd137e147bbd4a2fc24b7157443a472970554918cc47"
            },
            "downloads": -1,
            "filename": "drf-crud-proxy-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "701f49bd90aead3980b0a6a952c101a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6229,
            "upload_time": "2023-04-27T20:36:19",
            "upload_time_iso_8601": "2023-04-27T20:36:19.308670Z",
            "url": "https://files.pythonhosted.org/packages/6d/79/cca76bdabd5b32e0606c089bb16ea3c3a205b27454635b9787fd2c75ac8f/drf-crud-proxy-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-27 20:36:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "attevaltojarvi",
    "github_project": "drf-crud-proxy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "drf-crud-proxy"
}
        
Elapsed time: 0.07808s