Sets the `Database` that this model instance belongs to.
        This is done automatically when the instance is read from the database or written to it.

def set_database(self, db):
        '''
        Sets the `Database` that this model instance belongs to.
        This is done automatically when the instance is read from the database or written to it.
        '''
        # This can not be imported globally due to circular import
        from .database import Database
        assert isinstance(db, Database), "database must be database.Database instance"
        self._database = db