Django Rest Framework Expandable
Description
Expandable serializers for Django REST Framework. Allow for selective object expansion through query parameters or serializer class kwargs.
Installation
pip install django-rest-framework-expandable
Usage
# apps/users/api.serializers.py
# (User serializer)
class UserSerializer(ExpandableHyperlinkedModelSerializer):
class Meta:
model = User
fields = ("username", "id", ...)
# apps/users/api/fields.py
# (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/serializers.py
# 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()
...
Returns...
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",
...
}
}
Metadata
Release files for django-rest-framework-expandable 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-rest-framework-expandable-0.5.0.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_rest_framework_expandable-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.4 kB
Release files / django-rest-framework-expandable-0.5.0.tar.gz
| Download URL | django-rest-framework-expandable-0.5.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89f572eeeaba42464bdc9bfa7f0748a491bba18427d0ed0bccd7b424db3490b6
|
|
BLAKE2b-256 checksum How to use checksums |
de4a94cfc210665b0f836825861b56a5bd31ed609709e86851427b64764f431d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / django_rest_framework_expandable-0.5.0-py3-none-any.whl
| Download URL | django_rest_framework_expandable-0.5.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd3dcb5a4990c2151d6cefc86f1fb29780dd78980e75634d5562b4bef04a85d1
|
|
BLAKE2b-256 checksum How to use checksums |
9428a335a1bbf7d69cc1988977410686b1887d58a408155233579667ee519fa4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|