Noam Rotem and Yuval Adam
class User(Base):
__tablename__ = 'users'
id = Column(String(20), primary_key=True)
name = Column(String(15), nullable=False)
full_name = Column(Text)
description = Column(Text)
created = Column(DateTime)
location = Column(Text)
protected = Column(Boolean)
followers_count = Column(Integer)
friends_count = Column(Integer)
favourites_count = Column(Integer)
statuses_count = Column(Integer)
listed_count = Column(Integer)
imported = Column(DateTime(timezone=True), default=func.now())
updated = Column(DateTime(timezone=True), onupdate=func.now())
tags = Column(ARRAY(Text), nullable=False,
default=cast(array([], type_=Text), ARRAY(Text)))
followers = relationship('User', secondary=follows,
primaryjoin=id == follows.c.to_id,
secondaryjoin=id == follows.c.from_id,
order_by=follows.c.id,
backref='friends', lazy='subquery')
tweets = relationship('Tweet',
primaryjoin='User.id == foreign(Tweet.user_id)',
backref='user', lazy='subquery', viewonly=True)
__table_args__ = (
Index('ix_user_name_lower', func.lower('name')),
Index('ix_user_tags', tags, postgresql_using='gin'),
)