Skip to main content

nested serializer for django-rest-framework

Project description

Build Status Coverage Status

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

drf-nested-serializer-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_nested_serializer-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

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

Hashes for drf-nested-serializer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 194bf2c7d2bdcf74756a0c1b909e319da3b1f847aa840ab25e8ed6bca744f2ca
MD5 3a39dfbc10dc2396f19e3d0c1b6017fe
BLAKE2b-256 af0c6c089aa95fbd9ff5fd96dc3b7c329efbf85ef827a8b72fe2542c836b0c6e

See more details on using hashes here.

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

Hashes for drf_nested_serializer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02a87485ac5a5b208778acb7b9251b4fd6b811ab40d9e1ac2163975d3a510cf0
MD5 d90e5dc693c6e1322b24a6d7757989a2
BLAKE2b-256 22311d252a029fcb8acc58b7d0305af70d8a08458d6922b0ab22f1c73de3a6ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page