Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Expandable serializers for Django REST Framework

Project description

Django Rest Framework Expandable


Expandable serializers for Django REST Framework. Allow for selective object expansion through query parameters or serializer class kwargs.


pip install django-rest-framework-expandable


# apps/users/
# (User serializer)
class UserSerializer(ExpandableHyperlinkedModelSerializer):
  class Meta:
    model = User
    fields = ("username", "id", ...)

# apps/users/api/
# (User expandable serializer field)
class UserRelatedField(ExpandableHyperlinkedRelatedField):
  queryset = User.objects.all()
  lookup_field = "id"
  view_name = "api:user-detail"
  expand_settings = {
    "comparison_fields": ["id"],
    "serializers": [
        "paths": ["example.user"],
        "serializer": "apps.users.api.serializers.UserSerializer",
        "skipped": [],

# apps/example/api/
# Example serializer (using nested expandable serializer fields)
from apps.users.api.fields import UserRelatedField
from apps.another.api.fields import AnotherRelatedField

class ExampleSerializer(ExpandableHyperlinkedModelSerializer):
  another_related_field = AnotherRelatedField()
  user = UserRelatedField()


GET http://localhost:8000/api/examples/?expand=example.user
  id: 1,
  another_related_field: "http://localhost:8000/api/another/1",
  user: {
    id: 1,
    username: "Alex",

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-rest-framework-expandable, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size django_rest_framework_expandable-0.4.1-py3-none-any.whl (11.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-rest-framework-expandable-0.4.1.tar.gz (9.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page