class User(db.Model, UserMixin): __LOOKUP_ATTRS__ = [] id = db.Column(db.Integer, primary_key=True) created_at = db.Column('created_at', db.DateTime(), nullable=False, server_default=func.now()) email = db.Column(db.String(255), unique=True, nullable=False) name = db.Column(db.String(255)) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) last_login_at = db.Column(db.DateTime()) current_login_at = db.Column(db.DateTime()) last_login_ip = db.Column(db.String(255)) current_login_ip = db.Column(db.String(255)) login_count = db.Column(db.Integer()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) def __str__(self): return "<User #{} '{}' ({})>".format(self.id, self.name or "", self.email)
class Activity(db.Model): """ We record activities on objects through this """ @unique class Capabilities(Enum): pass __tablename__ = "activities" query_class = AccessQuery id = db.Column(db.Integer, primary_key=True) subject_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False) discriminator = db.Column('verb', db.String(100), nullable=False) created_at = db.Column('created_at', db.DateTime(), nullable=False, server_default=func.now()) object_id = db.Column(db.Integer, db.ForeignKey("objects.id"), nullable=True) whom_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=True) payload = db.Column('payload', JSONB, nullable=True) __mapper_args__ = {'polymorphic_on': discriminator} subject = db.relationship(User, backref=db.backref("activities"), foreign_keys=subject_id) object = db.relationship(Object, backref=db.backref("activities"))
class Object(db.Model): """ This is the primary base class for all kind of objects we know of inside the system """ @unique class Capabilities(Enum): # This type is to be shown in default lists # like 'top', 'latest' etc listed = 'listed' # If the type isn't listed but has `listed_for_activity` # it can show up in lists about activitys, for example # when an object got liked listed_for_activity = 'a_listable' # This can be searched for searchable = 'searchable' __tablename__ = "objects" query_class = ObjectQuery id = db.Column(db.Integer, primary_key=True) discriminator = db.Column('type', db.String(100), nullable=False) created_at = db.Column('created_at', db.DateTime(), nullable=False, server_default=func.now()) payload = db.Column('payload', JSONB, nullable=True) owner_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False) belongs_to = db.Column(db.Integer, db.ForeignKey("objects.id"), nullable=True) # children = db.relationship("Object", backref=db.backref('belongs_to', # remote_side=id)) __mapper_args__ = {'polymorphic_on': discriminator} owner = db.relationship(User, backref=db.backref('objects'))
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True, nullable=False) description = db.Column(db.String(255))