Ejemplo n.º 1
0
class Bookmark(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    description = db.Column(db.String(300))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    _tags = db.relationship('Tag',
                            secondary=tags,
                            lazy='joined',
                            backref=db.backref('bookmarks', lazy='dynamic'))

    @staticmethod
    def newest(num):
        return Bookmark.query.order_by(desc(Bookmark.date)).limit(num)

    @property
    def tags(self):
        return ",".join([t.name for t in self._tags])

    @tags.setter
    def tags(self, string):
        if string:
            self._tags = [
                Tag.get_or_create(name) for name in string.split(',')
            ]

    def __repr__(self):
        return "<Bookmark '{}': '{}'>".format(self.description, self.url)
Ejemplo n.º 2
0
class Blog(db.Model):

    __tablename__ = 'blogs'
    id = db.Column(db.Integer, primary_key=True)
    blog_id = db.Column(db.Text)
    dish_name = db.Column(db.String(60), nullable=False)
    dish_receipe = db.Column(db.Text)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    recipe_img = db.Column(db.String(80), nullable=True)

    email = db.Column(db.String(80),
                      db.ForeignKey('users.email'),
                      nullable=False)
    user = db.relationship('User',
                           backref=db.backref('blogs',
                                              lazy=True,
                                              cascade="all,delete"))

    def __init__(self, email, dish_name, dish_receipe, count):

        self.blog_id = str(email) + '-' + str(dish_name) + '-' + str(count)
        self.email = email
        self.dish_name = dish_name
        self.dish_receipe = dish_receipe

    def __repr__(self):
        return "Id: {} User: {} \n Receipe Name: {} \n Receipe: {} ".format(
            self.blog_id, self.email, self.dish_name, self.dish_receipe)
Ejemplo n.º 3
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Ejemplo n.º 4
0
class Owner(db.Model):

    __tablename__ = "owners"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text)
    puppy_id = db.Column(db.Integer, db.ForeignKey("puppies.id"))

    def __init__(self, name, puppy_id):
        self.name = name
        self.puppy_id = puppy_id
Ejemplo n.º 5
0
class Post(db.Model):
    # Name the table in database
    __tablename__ = 'posts'

    # Name of Column:
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text)
    content = db.Column(db.Text)

    # Connect the post to the member that owns it.
    # We use members.id because __tablename__='members'
    member_id = db.Column(db.Integer, db.ForeignKey('members.id'))

    def __init__(self, title, content, member_id):
        self.title = title
        self.content = content
        self.member_id = member_id
Ejemplo n.º 6
0
class BlogPost(db.Model):

    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post ID: {self.id}"
Ejemplo n.º 7
0
class UserInfo(db.Model):

    __tablename__ = 'usersinfo'

    user_id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(80), nullable=False)
    last_name = db.Column(db.String(80), nullable=False)
    email = db.Column(db.Integer, db.ForeignKey('users.email'), nullable=False)
    profile_image = db.Column(db.String(80),
                              nullable=False,
                              default='default.png')

    user = db.relationship('User',
                           backref=db.backref('usersinfo',
                                              lazy=True,
                                              cascade="all,delete"))

    def __init__(self, first_name, last_name):
        self.first_name = first_name
        self.last_name = last_name

    def __repr__(self):
        return "Name: {} {} Email: {}".format(self.first_name, self.last_name,
                                              self.user)
Ejemplo n.º 8
0
from datetime import datetime
from sqlalchemy import desc
from flask_login import UserMixin
from werkzeug.security import check_password_hash, generate_password_hash
from my_project import db

tags = db.Table(
    'bookmark_tag', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
    db.Column('bookmark_id', db.Integer, db.ForeignKey('bookmark.id')))


class Bookmark(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    description = db.Column(db.String(300))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    _tags = db.relationship('Tag',
                            secondary=tags,
                            lazy='joined',
                            backref=db.backref('bookmarks', lazy='dynamic'))

    @staticmethod
    def newest(num):
        return Bookmark.query.order_by(desc(Bookmark.date)).limit(num)

    @property
    def tags(self):
        return ",".join([t.name for t in self._tags])

    @tags.setter