Third Party Monitoring Module
  • Third Party Monitoring Module Documentation
  • INTRODUCTION
    • Glossary / Terminology
    • FAQ
    • Releases / Changelog*
    • Report an Issue / Contact us
  • PRODUCT / END-USER DOCUMENTATION
    • Overview
      • User rights and permissions
    • Third Party Monitoring Module Navigation
    • Overall User Interface
    • Third Party Monitors section
      • List of Third Party Monitors
      • TPM partner details screen
    • List of Visits section
      • List of Visits
      • Visit details
      • Statuses and corresponding actions
        • Draft
        • Assigned
        • TPM Accepted
        • TPM Rejected
        • Cancelled
        • TPM Reported
        • Sent Back to TPM
        • UNICEF Approved
      • Emails notifications flow
    • TPM workflow
  • TECHNICAL DOCUMENTATION
    • Architecture
    • Development Setup
    • Deployment / DevOps
    • Backend Module structure
    • Data Model
    • Fixtures & management commands
    • API Documentation
      • Error Handling
    • Synchronization with VISION
    • Permissions framework
    • FSM Transitions conditions
    • FSM Transitions in view
    • API Metadata
    • Serializer Mixins
    • Model Mixins
    • Tests
    • Attachments
    • Email links & Tokens Authorization
    • Frontend
      • Module structure
      • Build process
      • Tests
Powered by GitBook
On this page
  • Nested serializers
  1. TECHNICAL DOCUMENTATION

Serializer Mixins

Nested serializers

For editing nested data we use nested serializers. Mostly unicef_restlib.serializers.WritableNestedSerializerMixin should be used. It consists of three mixins:

DeletableSerializerMixin

This mixin allows us to delete nested instances. This can be done with the _delete flag. For example, when we want to delete nested instances having id 3 and 5, we can make update request with

{
    "<some nested serializer>": [
        {"id": 3, "_delete": true},
        {"id": 5, "_delete": true},
        ... some more updates together with delete parts
        {"id": 2, "value": "some new value"}
    ]
}

WritableNestedParentSerializerMixin

This mixin scan nested serializers during create or update call and then separate own data from nested. Then trying to validate nested data using found serializers and save everything atomically.

WritableNestedChildSerializerMixin

Another part of writable serializers, with logic connected to child instances. Firstly, we set pk field as writable and not required. This allows us to also define instances without pk, which should be created.

{
    "<some nested serializer>": [
        {"id": 3, "_delete": true},  # will be removed
        {"id": 2, "value": "some new value"},  # will be updated
        {"value": "some value"}  # new instance
    ]
}

Also, we divide validators to simple, which don't require instance and deferred, e.g. unique or unique together. This is required, because we may try to add conflicting information inside one request, for example users with the same unique email.

Parent & Child serializers are designed to be used together, just separated logically for easier understanding.

PreviousAPI MetadataNextModel Mixins

Last updated 6 years ago