nested serializer for django-rest-framework
Project description
DRF Nested Serializer
Nested Serializer support for Django Rest Framework.
Installation
pip install drf-nested-serializer
Example
class Goods(models.Model):
name = models.CharField(max_length=10)
category = models.CharField(max_length=20)
class GoodsImage(models.Model):
goods = models.ForeignKey(
Goods,
related_name='goods_images',
on_delete=models.CASCADE
)
image_key = models.CharField(max_length=10)
class GoodsSerializer(NestedModelSerializer):
class Meta:
model = Goods
fields = '__all__'
nested_fields = {'goods_images': 'goods'} # {related_name: field_name}
The above will allow to create the following queries
POST
{
"name": "string",
"category: "string",
"goods_images": [
{"image_key": "string"},
{"image_key": "string"},
{"image_key": "string"}
]
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf-nested-serializer-0.1.0.tar.gz.
File metadata
- Download URL: drf-nested-serializer-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
194bf2c7d2bdcf74756a0c1b909e319da3b1f847aa840ab25e8ed6bca744f2ca
|
|
| MD5 |
3a39dfbc10dc2396f19e3d0c1b6017fe
|
|
| BLAKE2b-256 |
af0c6c089aa95fbd9ff5fd96dc3b7c329efbf85ef827a8b72fe2542c836b0c6e
|
File details
Details for the file drf_nested_serializer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drf_nested_serializer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02a87485ac5a5b208778acb7b9251b4fd6b811ab40d9e1ac2163975d3a510cf0
|
|
| MD5 |
d90e5dc693c6e1322b24a6d7757989a2
|
|
| BLAKE2b-256 |
22311d252a029fcb8acc58b7d0305af70d8a08458d6922b0ab22f1c73de3a6ca
|