class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    author = db.Column(db.String(100))
    genre = db.Column(db.String(20))
    description = db.Column(db.String(1000))
    price = db.Column(db.Float)
    availability = db.Column(db.Boolean)

    publisher_name = db.Column(db.String(100), db.ForeignKey('publisher.name'))
    publisher = db.relationship('Publisher',
                                backref=db.backref('books', lazy='dynamic'))

    def __init__(self, title, author, genre, description, price, availability,
                 publisher):
        self.title = title
        self.author = author
        self.genre = genre
        self.description = description
        self.price = price
        self.availability = availability
        self.publisher = publisher

    def __repr__(self):
        return '<Book %r>' % self.title
Exemplo n.º 2
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    phone_number = db.Column(db.String(50), nullable=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    verification_code = db.Column(db.String(50), nullable=True)
    active = db.Column(db.Boolean(), default=False)
    has_verified_account = db.Column(db.Boolean(), default=False)
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def generate_verification_code(self):
        self.verification_code = random.randint(100000, 999999)

    def __str__(self):
        if self.first_name and self.last_name:
            return "{} {}".format(self.first_name, self.last_name)
        return self.email

    @property
    def full_name(self):
        if self.first_name and self.last_name:
            return f'{self.first_name} {self.last_name}'
        return ''
class Service(db.Model):
    __tablename__ = 'services'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    region = db.Column(db.String)
    size = db.Column(db.String)
    image = db.Column(db.String)
    ssh_keys = db.Column(db.String)
    backups = db.Column(db.Boolean)
    ipv6 = db.Column(db.Boolean)
    user_data = db.Column(db.String)
    private_networking = db.Column(db.String)
    volumes = db.Column(db.String)

    owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    owner = db.relationship('User', backref=db.backref('services', lazy=True))

    tags=db.relationship('Tag', secondary=service_tag, backref='services' )

    def insert(self):
        db.session.add(self)
        db.session.commit()

    def remove(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 4
0
class Drug(BioModel):
    name = db.Column(db.String(128))
    drug_bank_id = db.Column(db.String(32))
    description = db.Column(db.Text)

    target_genes_association_table = make_association_table('drug.id', Gene.id)

    target_genes = db.relationship(Gene,
                                   secondary=target_genes_association_table,
                                   backref=db.backref('drugs',
                                                      cascade='all,delete',
                                                      passive_deletes=True),
                                   cascade='all,delete',
                                   passive_deletes=True)

    type_id = db.Column(db.Integer, db.ForeignKey('drugtype.id'))
    type = db.relationship(DrugType, backref='drugs', lazy=False)

    group_association_table = make_association_table('drug.id', DrugGroup.id)

    groups = db.relationship(DrugGroup,
                             secondary=group_association_table,
                             collection_class=set,
                             backref='drugs')

    def to_json(self):
        return {
            'name': self.name,
            'type': self.type.name if self.type else '',
            'groups': [drug_group.name for drug_group in self.groups],
            'drugbank': self.drug_bank_id
        }
Exemplo n.º 5
0
class Post(db.Model):
    __tablename__ = 'ariticle'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    title = db.Column(db.String(100))
    body = db.Column(db.Text)
    issuing_time = db.Column(db.DateTime)
    body_html = db.Column(db.Text)
    comments = db.Column(db.Text)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship('User', backref=db.backref('articles'))

    def __init__(self, body):
        self.body = body
        self.body_html = ''

    def new_article(self):
        self.body_html = body_html(self.body)
        collection = {
            'username': current_user.username,
            'user_id': current_user.id,
            'body': self.body,
            'issuing_time': datetime.utcnow(),
            'body_html': self.body_html,
            'comments': []
        }
class Order(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    payment_method = db.Column(db.String(10))
    shipping_method = db.Column(db.String(10))
    date_placed = db.Column(db.Date())
    date_delivered = db.Column(db.Date())
    price = db.Column(db.Float)

    account_id = db.Column(db.String(100), db.ForeignKey('account.email'))
    account = db.relationship('Account',
                              backref=db.backref('orders', lazy='dynamic'))

    def __init__(self,
                 payment_method,
                 shipping_method,
                 account,
                 date_placed=None,
                 date_delivered=None):
        self.payment_method = payment_method
        self.shipping_method = shipping_method
        self.date_placed = datetime.now()
        self.date_delivered = self.date_placed + timedelta(days=10)
        self.account = account

    def __repr__(self):
        return '<Order %r>' % self.account_id
Exemplo n.º 7
0
class Rule(db.Model):
    __tablename__ = "Rule"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    description = db.Column(db.String(200))
    idAwsAccount = db.Column(db.Integer, db.ForeignKey('AwsAccount.id'))
    awsAccount = db.relationship("AwsAccount",
                                 foreign_keys=[idAwsAccount],
                                 cascade="merge")
    idRuleAction = db.Column(db.Integer, db.ForeignKey('RuleAction.id'))
    action = db.relationship("RuleAction",
                             foreign_keys=[idRuleAction],
                             cascade="merge")
    filters = db.relationship("RuleFilter",
                              uselist=True,
                              backref=db.backref('rule_rule_filter'),
                              cascade="save-update, merge, delete")
    idStatus = db.Column(db.Integer, db.ForeignKey('RuleStatus.id'))
    status = db.relationship("RuleStatus",
                             foreign_keys=[idStatus],
                             cascade="merge")
    idRuleType = db.Column(db.Integer, db.ForeignKey('RuleType.id'))
    type = db.relationship("RuleType",
                           foreign_keys=[idRuleType],
                           cascade="merge")
    timestamps = db.relationship("RuleTimestamp",
                                 uselist=True,
                                 backref=db.backref('rule_rule_timestamp'),
                                 cascade="save-update, merge, delete")

    def __init__(self,
                 name=None,
                 description=None,
                 idAwsAccount=None,
                 idRuleAction=None,
                 idStatus=None,
                 idRuleType=None,
                 filters=None,
                 timestamps=None):
        self.name = name
        self.description = description
        self.idAwsAccount = idAwsAccount
        self.idRuleAction = idRuleAction
        self.idStatus = idStatus
        self.idRuleType = idRuleType
        self.filters = filters
        self.timestamps = timestamps
Exemplo n.º 8
0
class Claim(db.Model):
    __tablename__ = 'claim'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    id_user_sender = db.Column(db.Integer, db.ForeignKey('users.id'))
    user_sender = db.relationship('User',
                                  foreign_keys=[id_user_sender],
                                  cascade='merge')
    id_user_reciver = db.Column(db.Integer, db.ForeignKey('users.id'))
    user_reciver = db.relationship('User',
                                   foreign_keys=[id_user_reciver],
                                   cascade="merge")
    id_category = db.Column(db.Integer, db.ForeignKey('claim_type.id'))
    category = db.relationship('ClaimType',
                               cascade='merge',
                               backref=db.backref('category'))
    id_status = db.Column(db.Integer, db.ForeignKey('claim_status.id'))
    status = db.relationship('ClaimStatus',
                             cascade='merge',
                             backref=db.backref('status'))
    date = db.Column(db.DateTime, nullable=False)
    id_property = db.Column(db.Integer, nullable=True)
    id_partnership = db.Column(db.Integer, nullable=True)
    date_end_claim = db.Column(db.DateTime, nullable=True)
    subject = db.Column(db.String, nullable=False)
    picture = db.Column(db.String, nullable=True)

    def __init__(self,
                 title=None,
                 subject=None,
                 id_category=None,
                 date=None,
                 id_user=None,
                 id_property=None,
                 id_partnership=None,
                 id_status=None,
                 picture=None):

        self.title = title
        self.subject = subject
        self.id_category = id_category
        self.date = date
        self.id_property = id_property
        self.id_partnership = id_partnership
        self.id_user = id_user
        self.id_status = id_status
        self.picture = picture
class Dungeon(db.Model):
    # Autoincrementing, unique primary key
    id = db.Column(db.Integer(), primary_key=True)
    level = db.Column(db.Integer)
    rooms = db.Column(db.Integer)
    treasures = db.Column(db.Integer)
    traps = db.Column(db.Integer)
    boss_level = db.Column(db.Boolean)
    xp_drop = db.Column(db.Integer)
    monsters = db.relationship(
        "Monster",
        secondary=monsters,
        lazy="subquery",
        backref=db.backref("dungeons", lazy=True),
    )

    def __repr__(self):
        return json.dumps(self.short())

    """
    short()
        short form representation of the Dungeon model
    """

    def short(self) -> dict:
        return {
            "id": self.id,
            "level": self.level,
            "rooms": self.rooms,
            "monsters": [m.short() for m in self.monsters],
        }

    """
    long()
        long form representation of the Dungeon model
    """

    def long(self) -> dict:
        return {
            "id": self.id,
            "level": self.level,
            "rooms": self.rooms,
            "treasures": self.treasures,
            "traps": self.traps,
            "boss_level": self.boss_level,
            "xp_drop": self.xp_drop,
            "monsters": [m.short() for m in self.monsters],
        }

    """
    all()
        returns all monsters
    """

    @classmethod
    def all(cls, detail=False) -> list:
        if query := cls.query.all():
            return [d.long() if detail else d.short() for d in query]
        else:
Exemplo n.º 10
0
class Producto(db.Model):
    id=db.Column(db.Integer,primary_key= True)
    nombre = db.Column(db.String(80))
    precio = db.Column(db.String(15))
    peso = db.Column(db.String(15))
    categoria_id = db.Column(db.Integer(),db.ForeignKey('categoria.id'))
    categoria = db.relationship('Categoria', backref = db.backref('productos',lazy=True))
        
class Favorite(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    account_id = db.Column(db.String(100), db.ForeignKey('account.email'))
    account = db.relationship('Account',
                              backref=db.backref('favorites', lazy='dynamic'))

    book_id = db.Column(db.Integer, db.ForeignKey('book.id'))
    book = db.relationship('Book',
                           backref=db.backref('favorites', lazy='dynamic'))

    def __init__(self, account, book):
        self.account = account
        self.book = book

    def __repr__(self):
        return '<Favorite %r>' % self.account_id
Exemplo n.º 12
0
class Experiment(db.Model):
    """
    Represents a testbed experiment.
    """
    __table_args__ = {'sqlite_autoincrement': True}

    Status = Enum("Status", "PREPARING RUNNING FINISHED")

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    status = db.Column(DatabaseEnum(Status, *[e.name for e in Status]))
    overlay = db.Column(db.String(50))
    creationTime = db.Column(db.DateTime)
    startTime = db.Column(db.DateTime)
    finishTime = db.Column(db.DateTime)

    nodes = db.relationship("Node", secondary=experimentHistory, \
            backref=db.backref("experiments", lazy="dynamic"), lazy="dynamic")

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

        for node in nodes:
            if not node.available:
                raise Exception("Some of the selected nodes are already \
                        running an experiment")
            node.activeExperiment = self

        self.nodes.extend(nodes)
        self.status = Experiment.Status.PREPARING
        self.creationTime = datetime.now()

    def __repr__(self):
        return "<Experiment %s - %s>" % (self.name, self.status)

    def start(self):
        if self.status != Experiment.Status.PREPARING:
            raise Exception("Experiment was already started.")

        for node in self.nodes:
            if node.status != Node.Status.READY:
                raise Exception("Node '%s' not ready." % node.id)

        self.status = Experiment.Status.RUNNING
        self.startTime = datetime.now()
        db.session.commit()

    def finish(self):
        if self.status == Experiment.Status.FINISHED:
            return

        self.status = Experiment.Status.FINISHED
        for node in self.nodes:
            node.activeExperiment = None
        self.finishTime = datetime.now()
        db.session.commit()
Exemplo n.º 13
0
class ReadingTip(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    _link = db.Column("link", db.String(120), nullable=False)
    read = db.Column(db.String(20), nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref=db.backref('tips', lazy=True))
    tags = db.relationship("Tag",
                           secondary=tips_to_tags_table,
                           backref=db.backref("tips"))

    def __init__(self, title, link, user, tags, **kwargs):
        super().__init__(**kwargs)
        self.title = title
        self.link = link
        self.user = user
        self.tags = tags

    @hybrid_property
    def link(self):
        return self._link

    @link.setter
    def link(self, link):
        if not link.startswith("http://") and not link.startswith("https://"):
            link = "http://" + link
        self._link = link

    @validates("title")
    def validate_title(self, _key, title):
        assert len(title) > 0, "Title must not be empty"
        assert len(title) <= 80, "Title is too long"
        return title

    @validates("_link")
    def validate_link(self, _key, link):
        if link.startswith("http://"):
            assert len(link) > len("http://"), "Link must not be empty"
        elif link.startswith("https://"):
            assert len(link) > len("https://"), "Link must not be empty"
        else:
            raise AssertionError("Link must start with protocol")
        assert len(link) <= 120, "Link is too long"
        return link
class Subscription(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    account_id = db.Column(db.String(100), db.ForeignKey('account.email'))
    account = db.relationship('Account',
                              backref=db.backref('subscriptions',
                                                 lazy='dynamic'))

    publisher_name = db.Column(db.String(100), db.ForeignKey('publisher.name'))
    publisher = db.relationship('Publisher',
                                backref=db.backref('subscriptions',
                                                   lazy='dynamic'))

    def __init__(self, account, publisher):
        self.account = account
        self.publisher = publisher

    def __repr__(self):
        return self.account_id
Exemplo n.º 15
0
class Survey(db.Model):
    id = db.Column(db.Integer, nullable=False, unique=True, primary_key=True)
    survey_name = db.Column(db.String(500), nullable=False)
    user_name = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref('surveys', lazy='dynamic'))

    def __init__(self, survey_name, uid):
        self.survey_name = survey_name
        self.user_name = uid
Exemplo n.º 16
0
class Candidate(db.Model):
    __tablename__ = 'candidate'
    candidate_id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(40), nullable=False)
    skills = db.relationship('Skill',
                             secondary=candidate_skills,
                             backref=db.backref('candidate', lazy='dynamic'))

    def __repr__(self):
        return '<Candidate %r %r>' % (self.title, self.skills)
Exemplo n.º 17
0
class Job(db.Model):
    __tablename__ = 'job'
    job_id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), unique=True, nullable=False)
    skills = db.relationship('Skill',
                             secondary=job_skills,
                             backref=db.backref('job', lazy='dynamic'))

    def __repr__(self):
        return '<Job %r %r>' % (self.title, self.skills)
class BookOrder(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer)

    order_id = db.Column(db.Integer, db.ForeignKey('order.id'))
    order = db.relationship('Order',
                            backref=db.backref('books', lazy='joined'))

    book_id = db.Column(db.Integer, db.ForeignKey('book.id'))
    book = db.relationship('Book',
                           backref=db.backref('orders', lazy='dynamic'))

    def __init__(self, order, book, quantity):
        self.order = order
        self.book = book
        self.quantity = quantity

    def __repr__(self):
        return '<Book-order %r>' % self.account_id
Exemplo n.º 19
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    api_key = db.Column(db.String(255), unique=True)
    name = db.Column(db.String(50))
    active = db.Column(db.Boolean())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    jenkins_key = db.Column(db.String(255))
    rundeck_key = db.Column(db.String(255))
Exemplo n.º 20
0
class TaskOwner(db.Model):
    __tablename__ = 'task_owners'
    id_task_owner = db.Column(Integer,
                              ForeignKey('users.id_user'),
                              primary_key=True)
    id_task = db.Column(Integer, ForeignKey('tasks.id_task'), primary_key=True)
    id_user = db.Column(Integer, ForeignKey('users.id_user'), primary_key=True)
    owner = db.relationship('User',
                            foreign_keys=[id_task_owner],
                            backref=db.backref('tasks_owner_per_task'))
    task = db.relationship(
        'Task',
        foreign_keys=[id_task],
        backref=db.backref('tasks_that_belong_to_the_owner'))

    def __init__(self, id_task_owner=None, id_task=None, id_user=None):
        self.id_task_owner = id_task_owner
        self.id_task = id_task
        self.id_user = id_user
class Cart(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer)
    cart = db.Column(db.String(10))

    account_id = db.Column(db.String(100), db.ForeignKey('account.email'))
    account = db.relationship('Account',
                              backref=db.backref('cart', lazy='dynamic'))

    book_id = db.Column(db.Integer, db.ForeignKey('book.id'))
    book = db.relationship('Book', backref=db.backref('carts', lazy='dynamic'))

    def __init__(self, account, book, quantity, cart='cart'):
        self.account = account
        self.book = book
        self.quantity = quantity
        self.cart = cart

    def __repr__(self):
        return '<Cart %r>' % self.account_id
Exemplo n.º 22
0
class ContentInLevelModel(db.Model):
    __tablename__ = 'coninlevels'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    level_id = db.Column(db.Integer,
                         db.ForeignKey('levels.id'),
                         primary_key=True)
    content_id = db.Column(db.Integer,
                           db.ForeignKey('contents.id'),
                           primary_key=True)
    weight = db.Column(db.Integer)

    content = db.relationship('ContentModel',
                              backref=db.backref("coninlevels",
                                                 cascade="all, delete-orphan"))
    level = db.relationship('LevelModel',
                            backref=db.backref("coninlevels",
                                               cascade="all, delete-orphan"))

    def __init__(self, level=None, content=None, weight=None):
        self.level = level
        self.content = content
        self.weight = weight

    def json(self):
        return {
            'level_id': self.level_id,
            'content_id': self.content_id,
            'weight': self.weight
        }

    @classmethod
    def find_by_level_id(cls, _id):
        return cls.query.filter_by(level_id=_id).all()

    @classmethod
    def find_by_level_id_first(cls, _id):
        return cls.query.filter_by(level_id=_id).first()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 23
0
class Surveyquestion(db.Model):
    id = db.Column(db.Integer, nullable=False, unique=True, primary_key=True)
    questionName = db.Column(db.String(500), nullable=False)
    questionType = db.Column(db.String(500), nullable=False)
    survey_name = db.Column(db.Integer, db.ForeignKey('survey.id'))
    survey = db.relationship('Survey',
                             backref=db.backref('questions', lazy='dynamic'))

    def __init__(self, questionName, questionType, surveyid):
        self.questionName = questionName
        self.questionType = questionType
        self.survey_name = surveyid
Exemplo n.º 24
0
class Comment(db.Model):
    __tablename__ = 'comment'

    id = db.Column(db.Integer, primary_key=True)
    creation_datetime = db.Column(db.DateTime)

    sku_id = db.Column(db.Integer, db.ForeignKey('sku.id'))
    sku = db.relationship('SKU',
                          backref=db.backref('comments', lazy='dynamic'))

    score = db.Column(db.SmallInteger)
    comment = db.Column(db.Text)
Exemplo n.º 25
0
class Surveyquestionanswer(db.Model):
    id = db.Column(db.Integer, nullable=False, unique=True, primary_key=True)
    answerString = db.Column(db.String(500), nullable=False)
    surveyquestion_name = db.Column(db.Integer,
                                    db.ForeignKey('surveyquestion.id'))
    surveyquestion = db.relationship('Surveyquestion',
                                     backref=db.backref('answers',
                                                        lazy='dynamic'))

    def __init__(self, ans, questionid):
        self.answerString = ans
        self.surveyquestion_name = questionid
Exemplo n.º 26
0
class User(db.Model, UserMixin):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    first = db.Column(db.String(80))
    last = db.Column(db.String(80))
    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'))
Exemplo n.º 27
0
class User(db.Model, UserMixin):
    """
	User model building off of flask-registration
	"""
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(60))
    password = db.Column(db.String())
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String())
    current_login_ip = db.Column(db.String())
    login_count = db.Column(db.Integer())
    created = db.Column(db.Date())
    company = db.Column(db.String)
    apis = db.relationship('API',
                           secondary=apis,
                           backref=db.backref('apis', lazy='dynamic'))
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('user'))
    onboarded = db.Column(db.Boolean(), default=False)
    returning_visitors = db.relationship('GoogleAnalyticsReturningVisitors',
                                         secondary=returning_visitors,
                                         backref=db.backref('user'))
    signups = db.relationship('GoogleAnalyticsSignups',
                              secondary=signups,
                              backref=db.backref('user'))

    def __repr__(self):
        return '<User %s>' % self.email

    def as_dict(self):
        return {
            'email': self.email,
            'roles': [str(role) for role in self.roles],
            'onboarded': self.onboarded
        }
Exemplo n.º 28
0
class Page(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    no = db.Column(db.Integer)
    link = db.Column(db.Unicode)

    chapter_id = db.Column(db.Integer, db.ForeignKey('chapter.id'))
    chapter = db.relationship('Chapter',
                              backref=db.backref('chapter', lazy='dynamic'))

    def __init__(self, no, link, chapter):
        self.no = no
        self.link = link
        self.chapter = chapter
Exemplo n.º 29
0
class Chapter(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Unicode)
    link = db.Column(db.Unicode)

    manga_id = db.Column(db.Integer, db.ForeignKey('manga.id'))
    manga = db.relationship('Manga',
                            backref=db.backref('manga', lazy='dynamic'))

    def __init__(self, title, link, manga):
        self.title = title
        self.link = link
        self.manga = manga
Exemplo n.º 30
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable=False)
    body = db.Column(db.Text, nullable=False)
    pub_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    author = db.Column(db.String(80), nullable=False)
    tags = db.relationship('Tag',
                           secondary=tags,
                           lazy='subquery',
                           backref=db.backref('posts', lazy=True))

    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
    category = db.relationship('Category',
                               backref=db.backref('posts', lazy=True))

    def __repr__(self):
        return '<Post %r>' % self.title

    def __str__(self):
        return self.title
Exemplo n.º 31
0
				print location
				formatted = location.address.split(',')
				self.address="%s %s" %(formatted[1].strip(),formatted[2].strip())
				self.city=formatted[-4].strip()
				self.state='CA'
				self.zipcode=formatted[-2].strip()
				self.stamp = set_stamp()
				db.session.commit()
				return location.address
			except Exception, e:
				print "REVERSE GEOCODER FINAL FAIL: %s." %(e)
				return "1 Gateway Plaza, Los Angeles, CA"

	# FKs
	features = db.relationship('Feature', secondary=placefeatures, 
		backref=db.backref('placefeatures', lazy='dynamic'))
	categories = db.relationship('Category', secondary=placecategories, 
		backref=db.backref('placecategories', lazy='dynamic'))

	resource_fields = {
		# for swagger
		'name': fields.String(),
		'description': fields.String(),
		# 'category': fields.Integer(),
		'pub_date': fields.DateTime( default=datetime.now() ),
		'address': fields.String(),
		'state': fields.String(),
		'city': fields.String(),
		'lat': fields.Float(default=0.0),
		'lon': fields.Float(default=0.0),
		'zipcode': fields.String(default='90012'),