diff --git a/app/models.py b/app/models.py index 41a7ca5ae1981892cd71edb8d121b4ca4cd077c7..41c8f27165bdf92f8283c9bd8561e031014a236f 100644 --- a/app/models.py +++ b/app/models.py @@ -111,6 +111,7 @@ class User(UserMixin, db.Model): role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) username = db.Column(db.String(64), unique=True, index=True) # Relationships + corpora = db.relationship('Corpus', backref='corpus', lazy='dynamic') jobs = db.relationship('Job', backref='job', lazy='dynamic') def __repr__(self): @@ -247,6 +248,27 @@ class Job(db.Model): return '<Job %r>' % self.title +class Corpus(db.Model): + """ + Class to define a corpus. + """ + __tablename__ = 'corpora' + # Primary key + id = db.Column(db.Integer, primary_key=True) + description = db.Column(db.String(64)) + title = db.Column(db.String(32)) + user_id = db.Column(db.Integer, db.ForeignKey('users.id')) + + def __init__(self, **kwargs): + super(Job, self).__init__(**kwargs) + + def __repr__(self): + """ + String representation of the corpus. For human readability. + """ + return '<Corpus %r>' % self.title + + ''' ' Flask-Login is told to use the application’s custom anonymous user by setting ' its class in the login_manager.anonymous_user attribute.