text: 
  from app import db
  
  
  class BaseModel:
      """Base for all models, providing save, delete and from_dict methods."""
  
      def __commit(self):
          """Commits the current db.session, does rollback on failure."""
          from sqlalchemy.exc import IntegrityError
          try:
              db.session.commit()
          except IntegrityError:
              db.session.rollback()
  
      def delete(self):
          """Deletes this model from the db (through db.session)"""
          db.session.delete(self)
          self.__commit()
  
      def save(self):
          """Adds this model to the db (through db.session)"""
          db.session.add(self)
          self.__commit()
          return self
  
      @classmethod
      def from_dict(cls, model_dict):
          return cls(**model_dict).save()