Skip to main content

drf_serializer_fields_permissions

pypi-version

Overview

This package provides a mixin for setting permissions to separate fields of ModelSerializer which uses DRF permission classes. You can hide or set a field as read-only for specific users.

Requirements

  • Python (3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11)

  • Django (2.0, 2.1, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2)

  • Django REST Framework (3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14)

Installation

Install using pip

$ pip install drf_serializer_fields_permissions

Example

To show a field only for staff users you need to add show_only_to field to the Meta class of a serializer. show_only_for field must be a dict with two keys - fields and permission_classes. permission_classes is a list or a tuple of permission classes. You can use built-in DRF permission or create your own, but you must override has_permission method of BasePermission class. fields is list or tuple of serializer fields which will be shown only to staff users, in our case.

from rest_framework import serializers
from rest_framework import permissions

from .models import Project

from fields_permissions.mixins import FieldPermissionMixin


class ProjectSerializer(FieldPermissionMixin, serializers.ModelSerializer):

    class Meta:
        model = Project
        fields = ('id', 'name', 'status', 'description', 'team_lead_user')

        show_only_for = {
            'fields': ('team_lead_user',),
            'permission_classes': (permissions.IsAdminUser,)
        }
        write_only_for = {
            'fields': ('status', 'description'),
            'permission_classes': (permissions.IsAdminUser,)
        }

Testing

Install testing requirements.

$ pip install -r requirements.txt

Run with runtests.

$ ./runtests.py

You can also use the excellent tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:

$ tox

Metadata

Release files for drf-serializer-fields-permissions 0.2.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-serializer-fields-permissions 0.2.0
File Size Uploaded Provenance Actions
drf_serializer_fields_permissions-0.2.0.tar.gz 5.1 kB Without provenance Details for drf_serializer_fields_permissions-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-serializer-fields-permissions 0.2.0
File Interpreter ABI Platform Actions
drf_serializer_fields_permissions-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for drf_serializer_fields_permissions-0.2.0-py2.py3-none-any.whl

Total release size: 9.6 kB

Release files / drf_serializer_fields_permissions-0.2.0.tar.gz

Download URL drf_serializer_fields_permissions-0.2.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
25fc401e90486afa9c76f59f77dc2f441277c732daed32b2f88aadb27ea56e97
BLAKE2b-256 checksum
How to use checksums
0c8123a0d8dc9bf0d8db792eaed1fe79d087bf49a150711512ccf04c68eb655c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / drf_serializer_fields_permissions-0.2.0-py2.py3-none-any.whl

Download URL drf_serializer_fields_permissions-0.2.0-py2.py3-none-any.whl
Size 4.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
54877a617b80d6fe03872d8cc32c4ece974aecbf7e1a432d70f0752db2b1a3d6
BLAKE2b-256 checksum
How to use checksums
c4a7a1102c1e5db404603bb43e37d673b263758a1c96089a969099654a6ff341
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for drf-serializer-fields-permissions 0.2.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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