コード例 #1
0
class RaceUnit(db.Model):
    __tablename__ = 'race_units'
    race_id = db.Column(db.Integer,
                        db.ForeignKey('races.id'),
                        primary_key=True)
    unit_id = db.Column(db.Integer,
                        db.ForeignKey('units.id'),
                        primary_key=True)
    created_at = db.Column(db.DateTime,
                           default=datetime.datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime)

    def __init__(self, race_id, unit_id):
        self.race_id = race_id
        self.unit_id = unit_id

    @property
    def serialize(self):
        """Return object data in easily serializable format"""
        return {
            'race_id': self.race_id,
            'unit_id': self.unit_id,
            'created_at': dump_datetime(self.created_at)
        }

    def __repr__(self):
        return '<RaceUnit race:%i unit:%i>' % (self.race_id, self.unit_id)
コード例 #2
0
ファイル: race.py プロジェクト: pranaya12/class
class Race(db.Model):
    __tablename__ = 'races'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True, nullable=False)
    description = db.Column(db.Text)
    created_at = db.Column(db.DateTime,
                           default=datetime.datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime)
    # This is the connection for many to many relationship between race and units
    units = db.relationship('Unit',
                            secondary=race_units,
                            backref=db.backref('race', lazy='dynamic'))

    def __init__(self, name, description):
        self.name = name
        self.description = description

    @property
    def serialize(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'units': self.units,
            'created_at': dump_datetime(self.created_at)
        }

    def __repr__(self):
        return '<Race %r>' % self.name
コード例 #3
0
class Friendship(db.Model):
    user = db.Column(db.Integer, primary_key=True)
    friend = db.Column(db.Integer, primary_key=True)

    def __init__(self, user, friend):
        self.user = user
        self.friend = friend
コード例 #4
0
ファイル: model.py プロジェクト: andrewjschuang/Turing
class Project(db.Model):
    """Project Class contains link to the user that interact with this project,
        the top level tasks related to id"""
    id = db.Column(db.Integer, primary_key=True)
    changed_at = db.Column(
        db.DateTime(), default=datetime.now(), onupdate=datetime.now())
    name = db.Column(db.String(80))
    description = db.Column(db.String(250))
    tasks = db.relationship('Task', secondary=project_tasks, lazy='subquery',
                            backref=db.backref('project', lazy=True))
    users = db.relationship('User', secondary=project_users, lazy='subquery',
                            backref=db.backref('project', lazy=True))

    def add_task(self, name, description, end_time):
        """Adds a new Task to this Project"""
        self.tasks.append(
            Task(name=name, description=description, end_time=end_time)
        )
        db.session.update(self)
        db.session.commit()

    def add_user(self, em_usname):
        """Adds existing user to thihs project"""
        user = User.query.filter_by(email=em_usname).first()
        if not user:
            user = User.query.filter_by(username=em_usname).first()
        if user:
            self.users.append(user)
            db.session.update(self)
            db.session.commit()
        else:
            raise Exception()
コード例 #5
0
class Subject(db.Model):
    __tablename__ = 'subjects'

    def __init__(self, name, description, student_year_id, module_id):
        self.name = name
        self.description = description
        self.student_year_id = student_year_id
        self.module_id = module_id

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    description = db.Column(db.String(200))

    student_year_id = db.Column(db.Integer, db.ForeignKey('student_years.id'))
    student_year = db.relationship('StudentYear',
                                   uselist=False,
                                   back_populates='subject')

    # TODO jedan predmet moze na vise modula
    module_id = db.Column(db.Integer, db.ForeignKey('modules.id'))
    module = db.relationship('Module', uselist=False, back_populates='subject')

    topics = db.relationship('Topic', back_populates='subject')
    proffessors = db.relationship('User',
                                  secondary=ProffessorSubject,
                                  back_populates='subjects')
    consultations = db.relationship('Consultation', back_populates='subject')

    def serialize(self):
        return {'id': self.id, 'name': self.name, 'description': self.description, \
                'studentYearId': self.student_year_id, 'moduleId': self.module_id}
コード例 #6
0
class UserTokens(db.Model, BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    token = db.Column(db.String, nullable=False)
    deleted = db.Column(db.Boolean, nullable=False, default=False)

    @staticmethod
    #def create_new_token(self, user_id):
    def create_new_token(user_id):
        UserTokens._deactivate_current_token(user_id)
        user_token = True
        while user_token != None:
            token = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for i in range(45))
            user_token = UserTokens.query.filter(
                UserTokens.token == token,
                UserTokens.user_id == user_id).first()
        UserTokens(user_id=user_id, token=token).insert()
        return token

    @staticmethod
    def _deactivate_current_token(user_id):
        user_token = UserTokens.query.filter(
            UserTokens.user_id == user_id,
            UserTokens.deleted == False).first()
        if user_token is not None:
            user_token.deleted = True
            user_token.save()
コード例 #7
0
class SensorNode(db.Model):
    __tablename__ = "sensor_node"
    id = db.Column(db.Integer, primary_key=True)
    mac = db.Column(db.Integer, nullable=False)
    name = db.Column(db.String, nullable=True)
    location = db.Column(db.String, nullable=True)
    sensors = db.relationship("Sensor", backref="sensor_node", lazy='joined')
    
コード例 #8
0
class Director(db.Model):
	__tablename__  = 'directors'

	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.Text())
	movies = db.relationship('Movie', backref='director', lazy='dynamic') # WHAT IS THIS DOING?

	def __init__ (self, name):
		self.name = name
コード例 #9
0
class Tag(db.Model):
	__tablename__ = 'tags'

	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.Text()) #WHY IS THIS A METHOD IF INTEGER IS NOT
	#THERE IS NO MOVIES COLUMN< HOW DOES THIS WORK?
	
	def __init__(self, name):
		self.name = name
コード例 #10
0
class Sensor(db.Model):
    __tablename__ = "sensor"
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.Integer)
    threshold = db.Column(db.Float, nullable=False)
    greater_than_or_eq = db.Column(db.Boolean, nullable=False, default=True)
    sensor_node_id = db.Column(db.Integer, db.ForeignKey("sensor_node.id"))
    readings = db.relationship("SensorReading",
                               backref="sensor",
                               lazy='dynamic')
コード例 #11
0
class SystemMergeField(db.Model):
    __tablename__ = "system_merge_field"
    id = db.Column(db.Integer, primary_key=True)
    tag = db.Column(db.String(50))
    name = db.Column(db.String(200))
    description = db.Column(db.Text, nullable=True)
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
コード例 #12
0
class Hashtag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    hashtag = db.Column(db.String(30), unique=True)

    # Note: could not create table with hashtag being primary key as well
    # post_hashtag refs hashtag as a foreign key and foreign keys must be unique
    # having id and hashtag both as primary keys does not gurantee that either is
    # unique by itself

    def __repr__(self):
        return '<Hashtag>'
コード例 #13
0
class Town(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(500), unique=True)
    region = db.Column(db.String(500))

    def __init__(self, name, region):
        self.name = name
        self.region = region

    def __repr__(self):
        return '<Town %r>' % self.name
コード例 #14
0
class Location(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    place_name = db.Column(db.String(120), nullable=False)
    latitude = db.Column(db.Numeric(10, 8), nullable=False)
    longitude = db.Column(db.Numeric(11, 8), nullable=False)

    # gps = db.Column(db.Integer)
    # city = db.Column(db.String(30))
    # country = db.Column(db.String(30))

    def __repr__(self):
        return '<Location>'
コード例 #15
0
class DataView_Unsubscribe(db.Model):
    __tablename__ = "data_view_unsubscribe"
    id = db.Column(db.Integer, primary_key=True)
    brand_id = db.Column(db.Integer, db.ForeignKey('brand.id'))
    campaign_id = db.Column(db.Integer, db.ForeignKey("campaign.id"))
    email_id = db.Column(db.String(50))
    email_address = db.Column(db.String(200))
    unique_email_id = db.Column(db.String(200))
    list_id = db.Column(db.Integer, db.ForeignKey("list.id"))
    event_date = db.Column(db.TIMESTAMP)
    campaign_title = db.Column(db.String(200), nullable=True)
    unsubscribe_type = db.Column(db.String(200), nullable=True)
コード例 #16
0
class PostLike(db.Model):
    pid = db.Column(db.ForeignKey("post.pid", ondelete="CASCADE"),
                    nullable=False,
                    primary_key=True)
    uid = db.Column(db.ForeignKey("user.id", ondelete="CASCADE"),
                    nullable=False,
                    primary_key=True,
                    index=True)
    timestamp = db.Column(db.DateTime)

    def __repr__(self):
        return '<PostLike>'
コード例 #17
0
class CommentLike(db.Model):
    comment_id = db.Column(db.ForeignKey("comment.comment_id",
                                         ondelete="CASCADE"),
                           nullable=False,
                           primary_key=True)
    uid = db.Column(db.ForeignKey("user.id", ondelete="CASCADE"),
                    nullable=False,
                    primary_key=True)
    timestamp = db.Column(db.DateTime)

    def __repr__(self):
        return '<CommentLike>'
コード例 #18
0
class Comment(db.Model):
    comment_id = db.Column(db.Integer, primary_key=True)
    pid = db.Column(db.ForeignKey("post.pid", ondelete="CASCADE"),
                    nullable=False,
                    index=True)
    uid = db.Column(db.ForeignKey("user.id", ondelete="SET NULL"),
                    nullable=False)
    comment = db.Column(db.String(300))
    timestamp = db.Column(db.DateTime, index=True)

    def __repr__(self):
        return '<Comment>'
コード例 #19
0
class UserSession(db.Model):
    __tablename__ = "user_session"
    __table_args__ = {'useexisting': True}
    id = db.Column(db.Integer, primary_key=True)
    token = db.Column(db.String(50))
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    created = db.Column(db.DateTime)
    last_used = db.Column(db.DateTime)

    def __init__(self, user=None):
        self.token = str(uuid.uuid4())
        self.user_id = user
        self.created = datetime.datetime.now()
コード例 #20
0
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(500))
    town = db.Column(db.Integer, db.ForeignKey('town.id'))
    status = db.Column(db.String(500), default='alive')

    def __init__(self, name, town, status):
        self.name = name
        self.town = town
        self.status = status

    def __repr__(self):
        return '<Person %r>' % self.name
コード例 #21
0
ファイル: author.py プロジェクト: rohanpai/library-flask-app
class Author(db.Model):

    __tablename__ = 'authors'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text())
    books = db.relationship('Book', backref='author', lazy='dynamic', cascade='all, delete-orphan')

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return 'id: {}, name: {}'.format(self.id, self.name)
コード例 #22
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)
    # privacy should only ever be "everyone" or "friends"
    privacy = db.Column(db.String(20))

    def __init__(self, username, email, privacy):
        self.username = username
        self.email = email
        self.privacy = privacy

    def __repr__(self):
        return '<User %r>' % self.username
コード例 #23
0
class Pedido(db.Model):
    __tablename__ = "Pedido"
    idPedido = db.Column(db.Integer, primary_key=True)
    idCliente = db.Column('idCliente', db.Integer,
                          db.ForeignKey("Cliente.idCliente"))
    total = db.Column(db.Float)
    detallePedido = relationship("DetallePedido", backref="Pedido")

    def __init__(self, idUsuario, total):
        self.idUsuario = idUsuario
        self.total = total

    def __repr__(self):
        return ''
コード例 #24
0
class UserStatus(db.Model):
    __tablename__ = 'user_statuses'

    def __init__(self, id, description):
        self.id = id
        self.description = description

    id = db.Column(db.Integer, primary_key=True, autoincrement=False)
    description = db.Column(db.String(50))

    user = db.relationship('User', back_populates='user_status', uselist=False)

    def serialize(self):
        return {'id': self.id, 'description': self.description}
コード例 #25
0
class VariateCampaignCombination(db.Model):
    __tablename__ = "variate_campaign_combination"
    id = db.Column(db.Integer, primary_key=True)
    variate_campaign_id = db.Column(db.Integer, db.ForeignKey("variate_campaign.id"))
    mailchimp_id = db.Column(db.String(50))
    email_id = db.Column(db.Integer, db.ForeignKey("email.id"))
    send_time = db.Column(db.TIMESTAMP, nullable=True)
    subject_line = db.Column(db.String(200))
    from_name = db.Column(db.String(200))
    reply_to = db.Column(db.String(200))
    recipients = db.Column(db.Integer)
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
コード例 #26
0
class Movie(db.Model):
    __tablename__ = 'movies'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text())
    director_id = db.Column(db.Integer, db.ForeignKey('directors.id'))
    tags = db.relationship('Tag',
                           secondary='movie_tags',
                           backref=db.backref('movies', lazy='dynamic'))

    #GOT WEIRD ERROR WHEN 'Tag' was 'tag'
    #WHAT DOES SECONDARY DO? WHAT DOES LAZY DO?
    def __init__(self, title, director_id):
        self.title = title
        self.director_id = director_id
コード例 #27
0
class Estado(db.Model):
    __tablename__ = 'Estado'
    idEstado = db.Column(db.Integer, primary_key=True)
    nombreEstado = db.Column(db.String(20))
    numEstado = db.Column(db.Integer)
    zona = db.Column(db.String(10))
    usuario = relationship("Usuario", backref="Estado")

    def __init__(self, nombreEstado, numEstado, zona):
        self.nombreEstado = nombreEstado
        self.numEstado = numEstado
        self.zona = zona

    def __repr__(self):
        return ''
コード例 #28
0
ファイル: book.py プロジェクト: rohanpai/library-flask-app
class Book(db.Model):

    __tablename__ = 'books'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text())
    author_id = db.Column(db.Integer, db.ForeignKey('authors.id'))

    def __init__(self, title, author_id):
        self.title = title
        self.author_id = author_id

    def __repr__(self):
        return 'id: {}, title: {}, author_id: {}'.format(
            self.id, self.title, self.author_id)
コード例 #29
0
ファイル: image.py プロジェクト: milica-beep/e-ques
class Image(db.Model):
    __tablename__ = 'images'

    id = db.Column(db.Integer, primary_key=True)
    path = db.Column(db.String(50), nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    user = db.relationship('User', back_populates='image')

    answer_id = db.Column(db.Integer, db.ForeignKey('answers.id'))
    answer = db.relationship('Answer', back_populates='images')

    def serialize(self):
        return {'id': self.id, 'path': self.path, 'userId': self.user_id, \
                'answerId': self.answer_id}
コード例 #30
0
class Proveedor(db.Model):
    __tablename__ = 'Proveedor'
    idProveedor = db.Column(db.Integer, primary_key=True)
    nombre = db.Column(db.String(20), unique=True)
    rfc = db.Column(db.String(13))
    telefono = db.Column(db.String(10))
    medcamento = relationship("Medicamento", backref="Proveedor")

    def __init__(self, nombre, rfc, telefono):
        self.nombre = nombre
        self.rfc = rfc
        self.telefono = telefono

    def __repr__(self):
        return ''