You can use the hybrid_property decorator to define an attribute on your class:
class Contact(db.Model):
...
@hybrid_property
def organization_id(self):
return self.company.organization_id if self.company else None
Using contact.organization_id
will load the company
using the foreign key relationship.
CLICK HERE to find out more related problems solutions.