class MemberModel(DB.Model):
    __tablename__ = "members"
    id = DB.Column(DB.String(), primary_key=True)
    lifegroup = DB.Column(DB.String(),
                          DB.ForeignKey('lifegroups.name', ondelete='CASCADE'))
    name = DB.Column(DB.String(), nullable=False)
    seats = DB.Column(DB.Integer(), default=0)
    suburb = DB.Column(DB.String(), nullable=False)

    def __repr__(self):
        return '<Member %r>' % self.name
Exemplo n.º 2
0
class Role(DB.Model, RoleMixin):
    id = DB.Column(DB.Integer(), primary_key=True)
    name = DB.Column(DB.String(80), unique=True)
    description = DB.Column(DB.String(255))
Exemplo n.º 3
0
            ("neutral", self.reactions_num(ReactionsType.neutral)),
            ("smile", self.reactions_num(ReactionsType.smile)),
            ("funny", self.reactions_num(ReactionsType.funny))]
        reactions_data = [item for item in reactions_data if item[1] > 0]
        reactions_data = sorted(reactions_data, key=itemgetter(1), reverse=True)
        return reactions_data

    def add_reaction(self, reaction_type):
        """method called after a user made reaction"""
        new_reaction = JokeReaction(joke_id=self.id, reaction_type=reaction_type)
        DB.session.add(new_reaction)
        DB.session.commit()

# Define models
roles_users = DB.Table('roles_users',
        DB.Column('user_id', DB.Integer(), DB.ForeignKey('user.id')),
        DB.Column('role_id', DB.Integer(), DB.ForeignKey('role.id')))

class Role(DB.Model, RoleMixin):
    id = DB.Column(DB.Integer(), primary_key=True)
    name = DB.Column(DB.String(80), unique=True)
    description = DB.Column(DB.String(255))

class User(DB.Model, UserMixin):
    id = DB.Column(DB.Integer, primary_key=True)
    email = DB.Column(DB.String(255), unique=True)
    password = DB.Column(DB.String(255))
    active = DB.Column(DB.Boolean())
    confirmed_at = DB.Column(DB.DateTime())
    roles = DB.relationship('Role', secondary=roles_users,
                            backref=DB.backref('users', lazy='dynamic'))