The File DocType has two fields called attached_to_doctype
and attached_to_name
.
So let’s say you want to attach a file to a Customer. You’d do it like this:
file = frappe.get_doc("File", "4ab1a860dc")
file.attached_to_doctype = "Customer"
file.attached_to_name = "John"
file.save()