How to create doc in another DocType on creation of one doc?

When I create a doc in Attendance doctype, I also want to create a doc of another doctype.
I am aware that I can simply do frappe.get_doc and then pass key-value pairs and use .save() or .insert() to create that another doc. But what I want is this creation of that another doc should only happen once this attendance doc is saved.
I am looking for solution in python server script.

Currently what happens is →
when i create attendance doc, stuff from attendance.py runs, it encounters other_doc.save() or .insert(), then it first creates that other doc and after that finally creates attendance doc.

What i want to happen is →
When I create attendance doc, it should create itself first, once it saves itself in db, only then it should create that other doc.

I am new to frappe, any help is much appreciated.