{"id":17720172,"url":"https://github.com/gregschmit/drf-action-serializer","last_synced_at":"2025-04-16T14:36:58.822Z","repository":{"id":57424022,"uuid":"199328314","full_name":"gregschmit/drf-action-serializer","owner":"gregschmit","description":"A serializer for the Django Rest Framework that supports per-action serialization of fields.","archived":false,"fork":false,"pushed_at":"2021-01-03T23:55:52.000Z","size":26,"stargazers_count":54,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-08T09:37:54.227Z","etag":null,"topics":["django-rest-framework","rest-api","serialization","serializer"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/drf-action-serializer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gregschmit.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["gregschmit"],"custom":["https://www.paypal.me/schmitgreg"]}},"created_at":"2019-07-28T19:24:38.000Z","updated_at":"2023-10-24T10:39:30.000Z","dependencies_parsed_at":"2022-09-17T19:24:05.555Z","dependency_job_id":null,"html_url":"https://github.com/gregschmit/drf-action-serializer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Fdrf-action-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Fdrf-action-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Fdrf-action-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Fdrf-action-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregschmit","download_url":"https://codeload.github.com/gregschmit/drf-action-serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249250895,"owners_count":21237963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django-rest-framework","rest-api","serialization","serializer"],"created_at":"2024-10-25T15:26:29.346Z","updated_at":"2025-04-16T14:36:58.796Z","avatar_url":"https://github.com/gregschmit.png","language":"Python","funding_links":["https://github.com/sponsors/gregschmit","https://www.paypal.me/schmitgreg"],"categories":[],"sub_categories":[],"readme":"Action Serializer\n=================\n\n.. image:: https://travis-ci.org/gregschmit/drf-action-serializer.svg?branch=master\n    :alt: TravisCI\n    :target: https://travis-ci.org/gregschmit/drf-action-serializer\n\n.. image:: https://img.shields.io/pypi/v/drf-action-serializer\n    :alt: PyPI\n    :target: https://pypi.org/project/drf-action-serializer/\n\n.. image:: https://coveralls.io/repos/github/gregschmit/drf-action-serializer/badge.svg?branch=master\n    :alt: Coveralls\n    :target: https://coveralls.io/github/gregschmit/drf-action-serializer?branch=master\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :alt: Code Style\n    :target: https://github.com/ambv/black\n\nSource: https://github.com/gregschmit/drf-action-serializer\n\nPyPI: https://pypi.org/project/drf-action-serializer/\n\nAction Serializer is a Django Rest Framework extension package that provides a\nSerializer that implements per-action field configuration for use in your drf-powered\nAPI.\n\n**The Problem**: When building APIs, often you want different serializers for different\nactions, such as less fields on a list view vs a detail view. Normally you would have to\nbuild multiple Serializers to support this.\n\n**The Solution**: This app provides the ``ModelActionSerializer`` which allows you to\neasily configure per-action serialization.\n\n\nHow to Use\n==========\n\n.. code-block:: shell\n\n    $ pip install drf-action-serializer\n\nIn your serializer, inherit from ``action_serializer.ModelActionSerializer``.\n\nIn your serializer, you can add an ``action_fields`` dictionary to the ``Meta`` class\nand use ``fields``, ``exclude``, and ``extra_kwargs`` under the action key. The example\nin this project shows how to render a smaller list of attributes for a list view\ncompared to the detail view.\n\n.. code-block:: python\n\n    from django.contrib.auth.models import Group\n    from action_serializer import ModelActionSerializer\n\n\n    class GroupActionSerializer(ModelActionSerializer):\n        \"\"\"\n        An example serializer for the Django ``Group`` model, where the ``list`` action\n        causes less fields to be serialized than normal.\n        \"\"\"\n\n        class Meta:\n            model = Group\n            fields = (\"id\", \"name\", \"permissions\")\n            action_fields = {\"list\": {\"fields\": (\"id\", \"name\")}}\n\nIn your ViewSet, just set the serializer like normal:\n\n.. code-block:: python\n\n    from rest_framework.viewsets import ModelViewSet\n\n\n    class GroupViewSet(ModelViewSet):\n        \"\"\"\n        An example viewset for the Django ``Group`` model.\n        \"\"\"\n\n        serializer_class = GroupActionSerializer\n        queryset = Group.objects.all()\n\n\nTests\n=====\n\n.. code-block:: shell\n\n    $ python manage.py test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregschmit%2Fdrf-action-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregschmit%2Fdrf-action-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregschmit%2Fdrf-action-serializer/lists"}