Created
May 14, 2020 03:34
-
-
Save witchapong/24530bae670a3a5551ab4cc4a917d086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from db import db | |
| class PhraseModel(db.Model): | |
| __tablename__ = 'phrases' | |
| id = db.Column(db.Integer, primary_key=True) | |
| value = db.Column(db.String(200)) | |
| intent_id = db.Column(db.Integer, db.ForeignKey('intents.id')) | |
| intent = db.relationship('IntentModel') | |
| def __init__(self, value, intent_id): | |
| self.value = value | |
| self.intent_id = intent_id | |
| def json(self): | |
| return {'id':self.id, | |
| 'value':self.value, | |
| 'intent_id':self.intent_id} | |
| @classmethod | |
| def find_by_value(cls, value): | |
| return cls.query.filter_by(value=value).first() | |
| @classmethod | |
| def find_by_id(cls,_id): | |
| return cls.query.filter_by(id=_id).first() | |
| def save_to_db(self): | |
| db.session.add(self) | |
| db.session.commit() | |
| def delete_from_db(self): | |
| db.session.delete(self) | |
| db.session.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment