Skip to main content

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

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).

# 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!

Metadata

Release files for drf-crud-proxy 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-crud-proxy 0.5.0
File Size Uploaded Provenance
drf_crud_proxy-0.5.0.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-crud-proxy 0.5.0
File Interpreter ABI Platform
drf_crud_proxy-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / drf_crud_proxy-0.5.0.tar.gz

Download URL drf_crud_proxy-0.5.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7317f62998d423fd6d3db6bcc59ce7a0b37b06c1e62efd4a07fa8d0cfaa38bc7
BLAKE2b-256 checksum
How to use checksums
edd286b1d881744fa138dd193bfec30df03c8f6ffa85473487573bf2d622f20b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.8

Release files / drf_crud_proxy-0.5.0-py3-none-any.whl

Download URL drf_crud_proxy-0.5.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4e1f64dbeffe05bc9573fc856c561dc03298d2990805073b5a34ce1b28e2eca
BLAKE2b-256 checksum
How to use checksums
94b1d619c4fa51949b27d213244d0848b6153b2b37b250acd2c5980810527e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.8

Security for drf-crud-proxy 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page