Validate Data in child table python

Hello everyone, how can I validate data in a child table python file?. I want to do it in python so that if it is done also via API the data is validated, I tried to add the validate function in the py file in the child table doctype but it is not called when a record it created.

Try calling your child’s validation methods from the parent’s validate hook:

class ParentDoc(Document):
    def validate(self):
        for row in self.my_child_table:
            row.validate_not_true()
class ChildDoc(Document):
    def validate_not_true(self):
        if not True:
            frappe.throw("not True")

This will work thank you @rmeyer, but not the solution I was looking forward to, as I wanted to do it in the child table py file. I also wanted to do on_trash, on_update, and others. Also, the table is in many doctypes.

You can use inheritance, so the many parent DocTypes can use the same validation logic.

class SuperParent(Document):
    """Common controller for all ParentDocs"""
    def validate(self):
        for row in self.my_child_table:
            row.validate_not_true()
class ParentDoc1(SuperParent):
    """DocType containing ChildDoc table, using SuperParent's validation logic"""
    pass
class ParentDoc2(SuperParent):
    """DocType containing ChildDoc table, using SuperParent's validation logic"""
    pass
class ChildDoc(Document):
    def validate_not_true(self):
        if not True:
            frappe.throw("not True")

(SuperParent in this case is not a DocType, just a controller.)

We dedicded to not use childtable, but thank you, although this will work not what we wanted.