def METHOD_NAME(self, instance: Department, validated_data: dict):
    instance.category_set.clear()
    for category_department_validated_data in validated_data:
        category_department_validated_data['department'] = instance
        category_department = CategoryDepartment(**category_department_validated_data)
        category_department.save()