All Projects → evenicoulddoit → Django Rest Framework Serializer Extensions

evenicoulddoit / Django Rest Framework Serializer Extensions

Licence: other
Extensions to help DRY up Django Rest Framework serializers

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Rest Framework Serializer Extensions

Django Hashid Field
Django Model Field that uses Hashids to obscure the value
Stars: ✭ 256 (+42.22%)
Mutual labels:  hashids, django, django-rest-framework
Django Trench
django-trench provides a set of REST API endpoints to supplement django-rest-framework with multi-factor authentication (MFA, 2FA). It supports both standard built-in authentication methods, as well as JWT (JSON Web Token).
Stars: ✭ 123 (-31.67%)
Mutual labels:  django, django-rest-framework
Crud App Vuejs Django
This is simple crud app and searchFilter made using vuejs and django. Used to explain the tutorial present on https://medium.com/@shubhambansal_89125/crud-app-using-vue-js-and-django-516edf4e4217 https://medium.com/@shubhambansal_89125/searchfilter-using-django-and-vue-js-215af82e12cd
Stars: ✭ 174 (-3.33%)
Mutual labels:  django, django-rest-framework
Django Structlog
Structured Logging for Django
Stars: ✭ 127 (-29.44%)
Mutual labels:  django, django-rest-framework
Paperweekly forum
paperweekly's forum
Stars: ✭ 118 (-34.44%)
Mutual labels:  django, django-rest-framework
Sarenka
OSINT tool - gets data from services like shodan, censys etc. in one app
Stars: ✭ 120 (-33.33%)
Mutual labels:  django, django-rest-framework
Djangorestframework Queryfields
Allows clients to control which fields will be sent in the API response
Stars: ✭ 170 (-5.56%)
Mutual labels:  django, django-rest-framework
Everbug
Django debug tool for browser
Stars: ✭ 114 (-36.67%)
Mutual labels:  django, django-rest-framework
Django Grpc Framework
gRPC for Django.
Stars: ✭ 162 (-10%)
Mutual labels:  django, django-rest-framework
Django Guid
Inject an ID into every log message from a Django request. ASGI compatible, integrates with Sentry, and works with Celery
Stars: ✭ 166 (-7.78%)
Mutual labels:  django, django-rest-framework
Usaspending Api
Server application to serve U.S. federal spending data via a RESTful API
Stars: ✭ 166 (-7.78%)
Mutual labels:  django, django-rest-framework
Hydroshare
HydroShare is a collaborative website for better access to data and models in the hydrologic sciences.
Stars: ✭ 117 (-35%)
Mutual labels:  django, django-rest-framework
Maria Quiteria
Backend para coleta e disponibilização dos dados 📜
Stars: ✭ 115 (-36.11%)
Mutual labels:  django, django-rest-framework
Lpoj
An open source online judge system base on Django REST framework and Vue.js !
Stars: ✭ 122 (-32.22%)
Mutual labels:  django, django-rest-framework
Bag Of Holding
An application to assist in the organization and prioritization of software security activities.
Stars: ✭ 114 (-36.67%)
Mutual labels:  django, django-rest-framework
Django Microservices
UNMAINTAINED
Stars: ✭ 124 (-31.11%)
Mutual labels:  django, django-rest-framework
Rest Api Basics
This is a basic guide on how to build a REST API with Django & Python. For much deeper depth, check out our new course on REST API: (https://kirr.co/90kxtx)
Stars: ✭ 171 (-5%)
Mutual labels:  django, django-rest-framework
Opentpod
Open Toolkit for Painless Object Detection
Stars: ✭ 106 (-41.11%)
Mutual labels:  django, django-rest-framework
Crudl Example Django
CRUDL with Django, DRF/Graphene and SQLite
Stars: ✭ 113 (-37.22%)
Mutual labels:  django, django-rest-framework
Django Vue Admin
基于RBAC模型权限控制的中小型应用的基础开发平台,前后端分离,后端采用django+django-rest-framework,前端采用vue+ElementUI,移动端采用uniapp+uView(可发布h5和小程序).
Stars: ✭ 157 (-12.78%)
Mutual labels:  django, django-rest-framework

Django REST framework serializer extensions

A collection of useful tools to DRY up your Django Rest Framework serializers

Full documentation: http://django-rest-framework-serializer-extensions.readthedocs.io/

build-status-image coverage-status-image pypi-version

Overview

Serializer extensions reduces the need for very similar serializers, by allowing the fields to be defined on a per-view/request basis. Fields can be whitelisted, blacklisted, and child serializers can be optionally expanded. Whatever fields you choose to use, your querysets can be optimized automatically to make the fewest database calls possible.

Support for HashIds is also provided. If you're currently exposing your internal IDs over a public API, we suggest you consider switching to HashIds instead.

⭐️ Lovingly open-sourced by Housekeep.

Requirements

Tested against:

Installation

Install using pip:

$ pip install djangorestframework-serializer-extensions

And add rest_framework_serializer_extensions to your INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'rest_framework_serializer_extensions'
)

Basic Usage

To activate the serializer extensions, add the SerializerExtensionsMixin to your serializers:

# serializers.py
from rest_framework.serializers import ModelSerializer
from rest_framework_serializer_extensions.serializers import SerializerExtensionsMixin

...

class OwnerSerializer(SerializerExtensionsMixin, ModelSerializer):
    class Meta:
        model = models.Owner
        fields = ('id', 'name')
        expandable_fields = dict(
            organization=OrganizationSerializer,
            cars=dict(
                serializer=SkuSerializer,
                many=True
            )
        )

And add the SerializerExtensionsAPIViewMixin to your API views:

from rest_framework.generics import RetrieveAPIView
from rest_framework_serializer_extensions.views import SerializerExtensionsAPIViewMixin

class RetriveOwnerAPIView(SerializerExtensionsAPIViewMixin, RetrieveAPIView):
    ...

Examples

Serializer extensions allows your API to re-use your serializers to fit a variety of use cases. The examples shown below use query parameters to modify the response, but individual views can interact with your serializers in much the same way.

>>> GET /owner/x4F/
{
  "id": 'x4F',
  "name": 'tyrell',
  "organization_id": 'kgD'
}
>>> GET /owner/x4F/?expand=organization
{
  "id": 'x4F',
  "name": 'tyrell',
  "organization_id": 'kgD',
  "organization": {
    "id": "kgD",
    "name": "E Corp"
  }
}
>>> GET /owner/x4F/?expand=cars__model&exclude=name
{
  "id": 'x4F',
  "organization_id": 'kgD',
  "cars": [
    {
      "id": "wf9",
      "variant": "P100D",
      "model": {
        "id": "ncX",
        "name": "Model S"
      }
    }
  ]
}
>>> GET /owner/x4F/?expand=cars&only=cars__variant
{
  "cars": [
    {
      "variant": "P100D",
    }
  ]
}

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

Documentation

To build the documentation, you’ll need to install mkdocs.

$ pip install mkdocs

To preview the documentation:

$ mkdocs serve
Running at: http://127.0.0.1:8000/

To build the documentation:

$ mkdocs build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].