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.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b98436d79db009e4bf980717b854f9fbabd6c3afd17b0841383407f1d9c19a1 |
|
MD5 | 5e22deeb4932024d2e43a410a1c8730b |
|
BLAKE2b-256 | 9e1d88e81374bf7307be3b7e63a894754b0b196a2b2888eb26638df0d60c6773 |
Close
Hashes for drf_nested_serializer-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06956622c5513858777c3765f5312e0a4abbee346a39af449e9a70ca685e6399 |
|
MD5 | 019ee60fbbc263f10760af7ca69eac11 |
|
BLAKE2b-256 | b9fe0b4adfa1b76a3de8585f64aca34293207d24e8cb86452874f8701a0ad4fe |