          if getattr(obj, '_related_data', None):
              for accessor_name, related in obj._related_data.items():
                  field = self.fields.get(accessor_name, None)
                  if isinstance(field, Serializer):
                      # TODO: Following will be needed for reverse FK
                      # if field.many:
                      #     # Nested reverse fk relationship
                      #     for related_item in related:
                      #         fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                      #         setattr(related_item, fk_field, obj)
                      #         self.save_object(related_item)
                      # else:
                      # Nested reverse one-one relationship
                      fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                      setattr(related, fk_field, obj)
                      self.save_object(related)
                  else:
                      # Reverse FK or reverse one-one
                      setattr(obj, accessor_name, related)
              del(obj._related_data)
  
 
</s>
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
          if getattr(obj, '_related_data', None):
              for accessor_name, related in obj._related_data.items():
                  field = self.fields.get(accessor_name, None)
                  if isinstance(field, Serializer):
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                    if field.many:
                        # Nested reverse fk relationship
                        for related_item in related:
                            fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                            setattr(related_item, fk_field, obj)
                            self.save_object(related_item)
                    else:
                        # Nested reverse one-one relationship
                        fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name
                        setattr(related, fk_field, obj)
                        self.save_object(related)
                  else:
                      # Reverse FK or reverse one-one
                      setattr(obj, accessor_name, related)
              del(obj._related_data)
  
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 one-many writable nested modelserializer support
rest_framework/serializers.py