def METHOD_NAME(self, validated_data):
    chapter_list_serializer = self.fields["chapters"]
    chapter_serializer = chapter_list_serializer.child
    chapter_ids = [chapter["id"] for chapter in validated_data if "id" in chapter]
    Chapter.objects.filter(module_id=self.context["module_pk"]).exclude(
        id__in=chapter_ids
    ).delete()
    for weight, chapter_data in enumerate(validated_data):
        chapter_data["weight"] = weight
        if "id" in chapter_data:
            instance = Chapter.objects.get(id=chapter_data["id"])
            assert instance.module_id == self.context["module_pk"]
            yield chapter_serializer.update(instance, chapter_data)
        else:
            yield chapter_serializer.create(chapter_data)