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
Close
Hashes for drf-nested-serializer-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 194bf2c7d2bdcf74756a0c1b909e319da3b1f847aa840ab25e8ed6bca744f2ca |
|
MD5 | 3a39dfbc10dc2396f19e3d0c1b6017fe |
|
BLAKE2b-256 | af0c6c089aa95fbd9ff5fd96dc3b7c329efbf85ef827a8b72fe2542c836b0c6e |
Close
Hashes for drf_nested_serializer-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02a87485ac5a5b208778acb7b9251b4fd6b811ab40d9e1ac2163975d3a510cf0 |
|
MD5 | d90e5dc693c6e1322b24a6d7757989a2 |
|
BLAKE2b-256 | 22311d252a029fcb8acc58b7d0305af70d8a08458d6922b0ab22f1c73de3a6ca |