コード例 #1
0
class User(db.Model, UserMixin):
	id = db.Column(db.Integer, primary_key=True)
	username = db.Column(db.String(20), unique=True, nullable=False)
	email = db.Column(db.String(120), unique=True, nullable=False)
	image_file = db.Column(db.String(120), nullable=False, default='default.jpg')
	password = db.Column(db.String(60), nullable=False)
	posts = db.relationship('Post', backref='author', lazy=True)
	comments = db.relationship('PostComment', backref='comment_author', lazy=True)
	models = db.relationship('UserModel', backref='model_author', lazy=True)

	def get_reset_token(self, expire_sec=1800):
		s = Serializer(current_app.config['SECRET_KEY'], expire_sec)
		return s.dumps({'user_id':self.id}).decode('utf-8')

	@staticmethod
	def verify_reset_token(token):
		s = Serializer(current_app.config['SECRET_KEY'])
		try:
			user_id = s.loads(token)['user_id']
		except:
			return None
		return User.query.get(user_id)

	def __repr__(self):
		return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #2
0
ファイル: models.py プロジェクト: annalun/flask_course
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    blog_id = db.Column(db.Integer, db.ForeignKey('blog.id'))
    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))
    title = db.Column(db.String(80))
    body = db.Column(db.Text)
    image = db.Column(db.String(255))
    slug = db.Column(db.String(256), unique=True)
    publish_date = db.Column(db.DateTime)
    live = db.Column(db.Boolean)

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

    comments = db.relationship('Comment', backref='posts', lazy='dynamic') # added
        
    @property
    def imgsrc(self):
        return uploaded_images.url(self.image)

    def __init__(self, blog, author, title, body, category, image=None, slug=None, publish_date=None, live=True):
            self.blog_id = blog.id
            self.author_id = author.id
            self.title = title
            self.body = body
            self.category = category
            self.image = image
            self.slug = slug
            if publish_date is None:
                self.publish_date = datetime.utcnow()
            self.live = live

    def __repr__(self):
        return '<Post %r>' % self.title
コード例 #3
0
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(80))
    email = db.Column(db.String(35), unique=True)
    username = db.Column(db.String(80), unique=True)
    password = db.Column(db.String(60))
    is_author = db.Column(db.Boolean)
    bio = db.Column(db.String(256))
    image = db.Column(db.String(255))

    posts = db.relationship('Post', backref='author', lazy='dynamic')
    blogs = db.relationship('Blog', backref='author', lazy='dynamic')

    @property
    def imgsrc(self):
        return uploaded_images.url(self.image)

    def __init__(self,
                 fullname,
                 email,
                 username,
                 password,
                 is_author=False,
                 bio=None,
                 image=None):
        self.fullname = fullname
        self.email = email
        self.username = username
        self.password = password
        self.is_author = is_author
        self.bio = bio
        self.image = image

    def __repr__(self):
        return '<Author %r>' % self.username
コード例 #4
0
ファイル: models.py プロジェクト: guilefoylegaurav/flask-blog
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def generate_token(self, expiration=600):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
            user = User.query.filter_by(id=data['id']).first()
            return user
        except:
            return None

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #5
0
ファイル: models.py プロジェクト: zaraki02/Flask-Blog-app
class Users(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique = True, nullable = False)
    email = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    image = db.Column(db.String(20), nullable=False, default='default.jpg')

    posts = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expires_sec= 1800):
        s = Serializer(app.config["SECRET_KEY"], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config["SECRET_KEY"])
        try:
            user_id = s.loads(token)['user_id']
        except:
            print("None!!!!!!!!!!!!!!!!!!!!!!!!")
            return None
        print("User is chill!!!!!!!!!!!!!!!!!!!")
        return Users.query.get(user_id)

    def __repr__(self):
        return f'User({self.id}, {self.username}, {self.image})'
コード例 #6
0
ファイル: models.py プロジェクト: bibishan-pandey/flask_blog
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.png')
    password = db.Column(db.String(60), nullable=False)

    # 1-many relationship i.e. one user can have many post but one post can have only one author with Post class
    posts = db.relationship('Post', backref='author', lazy=True)

    # password reset method with token
    def get_reset_token(self, expires_seconds=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_seconds)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #7
0
class User(db.Model, UserMixin):
    # create the columns of the User db
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(16), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image = db.Column(db.String(20), nullable=False, default='default.png')
    password = db.Column(db.String(60), nullable=False)

    # backref allows us to put the user as the 'author' in posts table
    posts = db.relationship('Post', backref='author', lazy=True)

    # create a reset token to reset the user account password
    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    # verify that the received token corresponds to a user in the db and return it
    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image}')"
コード例 #8
0
ファイル: models.py プロジェクト: tanneryilmaz/flask_website
class User(db.Model, UserMixin):
    ''' This class defines structure of the User object. Each user of the website is put into the database as an instance of this User class'''
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship(
        'Post', backref='author',
        lazy=True)  #grabs posts from the posts table by a specific author

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        '''this method defines how the object is printed'''
        return f"User('{self.username}','{self.email}','{self.image_file}')"
コード例 #9
0
ファイル: models.py プロジェクト: tejeshbhalla/Flask-Blog
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship(
        'POST', backref='author',
        lazy=True)  # lazy means it will return the data in one go

    #this posts col allows us to view the user who created the post
    def __repr__(self):
        return f"User('{self.username}','{self.email}','{self.image_file}')"

    def get_reset_token(self, expires_time=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_time)

        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_token(token):
        s = Serializer(app.config['SECRET_KEY'])

        try:
            user_id = s.loads(token)['user_id']

        except:
            return None

        return User.query.get(user_id)
コード例 #10
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    email = db.Column(db.String(40), nullable=False, unique=True)
    profile_picture = db.Column(db.String(20),
                                nullable=False,
                                default="joker.jpg")
    password = db.Column(db.String(40), nullable=False)
    posts = db.relationship('Posts', backref='author', lazy=True)

    # backref - to mention col name in related Class(table) lazy to be able to fetch all
    # posts using the author

    def get_reset_token(self, expires_sec=300):
        serial = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return serial.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        serial = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = serial.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.id}')"
コード例 #11
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    # This function generates a time-specific token
    # It takes the user_id of u.init_app(app)ser as payload and gernerate a long random string.
    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        # try-except block to test weather the token is valid or not
        # if the token is invalid or time limit has expired then we return none
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #12
0
ファイル: models.py プロジェクト: tim-hash/flask_app
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    # Don't forget later to have the hash with salt or lookup on the internet newer technique to hash passwords
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expire_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expire_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod  # tells python no need to expect the self argument
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None

        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #13
0
ファイル: models.py プロジェクト: Sumedh3113/Flask-Python
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)
    # it refers to other class posts as one user can have many posts
    # backref is used to get the user who created the post
    #lazy attribute is used to get all the posts created by a user
    # here we are referencing the Post class that's why we have Posts

    def get_reset_token(self, expires_sec=1800):
        # its 1800 sec i.e 30 min
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    # we are not using self keyword so we define staticmethod keyword 
    # to tell python do not expect self as argument we are only going to
    # use token
    
    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)


    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #14
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)

    #Basically, this does an additional query lets us see all posts made by this specific user
    posts = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):  #how our object is printed when we print it out
        return f"User('{self.username}','{self.email}','{self.image_file}')"
コード例 #15
0
class Orders(db.Model):
    order_id = db.Column(db.Integer, primary_key=True)
    order_number = db.Column(db.Integer, nullable=False)
    date_order = db.Column(db.DateTime(timezone=True), default=func.now())
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.user_id'),
                        nullable=False)
    shipper_id = db.Column(db.Integer,
                           db.ForeignKey('shipper.shipper_id'),
                           nullable=False)

    order_details = db.relationship('OrderDetails', backref='has', lazy=True)
    user = db.relationship('User', backref='ordered', lazy=True)
    shipper = db.relationship('Shipper', backref='managed', lazy=True)

    def __repr__(self):
        return f"Orders('order_id(PK): {self.order_id}, user_id(FK): {self.user_id}, shipper_id(FK):{self.shipper_id},  order_number: {self.order_number})"
コード例 #16
0
class Shipper(db.Model):
    shipper_id = db.Column(db.Integer, primary_key=True)
    company_name = db.Column(db.String(40), nullable=False)
    phone = db.Column(db.String(40), nullable=False)

    orders = db.relationship('Orders', backref='shipped', lazy=True)

    def __repr__(self):
        return f"Shipper('shipper_id (PK): {self.shipper_id}, company_name: {self.company_name}, phone: {self.phone}')"
コード例 #17
0
class Category(db.Model):
    category_id = db.Column(db.Integer, primary_key=True)
    category_name = db.Column(db.String(40), nullable=False)
    category_description = db.Column(db.String(100), nullable=False)

    products = db.relationship('Products', backref='contains', lazy=True)

    def __repr__(self):
        return f"Category('category_id(PK): {self.category_id}, category_name: {self.category_name}, category_description: {self.category_description}')"
コード例 #18
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)
コード例 #19
0
class OrderDetails(db.Model):
    order_details_id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer, nullable=False, default=1)
    price = db.Column(db.Float, nullable=False)
    total = db.Column(db.Float, nullable=False)
    user_id = db.Column(db.Integer, nullable=True)
    order_id = db.Column(db.Integer,
                         db.ForeignKey('orders.order_id'),
                         nullable=True)
    product_id = db.Column(db.Integer,
                           db.ForeignKey('products.product_id'),
                           nullable=False)

    order = db.relationship('Orders', backref='fromorder', lazy=True)
    product = db.relationship('Products', backref='includes', lazy=True)

    def __repr__(self):
        return f"OrderDetails('order_details_id(PK): {self.order_details_id}, product_id(FK): {self.product_id}, order_id(FK): {self.order_id}, quantity: {self.quantity}, price: {self.price}, total: {self.total}')"
コード例 #20
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}')"
コード例 #21
0
class User(db.Model, UserMixin):
    user_id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(40), nullable=False)
    last_name = db.Column(db.String(40), nullable=False)
    email = db.Column(db.String(40), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    address = db.Column(db.String(50), nullable=False)
    city = db.Column(db.String(40), nullable=False)
    state = db.Column(db.String(40), nullable=False)
    postcode = db.Column(db.String(40), nullable=False)
    country = db.Column(db.String(40), nullable=False)
    phone = db.Column(db.String(40), nullable=False)
    role = db.Column(db.Integer, nullable=False, default=0)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')

    orders = db.relationship('Orders', backref='buy', lazy=True)

    def get_id(self):
        return (self.user_id)

    def get_role(self):
        return self.role

    def set_admin(self):
        user = User.query.filter_by(user_id=self.user_id).first()
        user.role = 1
        db.session.commit()

    def set_user(self):
        user = User.query.filter_by(user_id=self.user_id).first()
        user.role = 0
        db.session.commit()

    def is_admin(self):
        return True if self.role == 1 else False

    def is_user(self):
        return True if self.role == 0 else False

    def get_reset_token(self, expires_seconds=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_seconds)
        return s.dumps({'user_id': self.user_id}).decode('utf-8')

    @staticmethod
    def verify_reset(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('user_id(PK): {self.user_id}, first_name: {self.first_name}, last_name: {self.last_name}, phone: {self.phone}, email: {self.email}, image: {self.image_file}')"
コード例 #22
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image = db.Column(db.String(20), nullable=False, default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    videos = db.relationship('Videos', backref='uploader', lazy=True)

    def __repr__(self):
        return f"User('{self.username}','{self.email}','{self.image}')"
コード例 #23
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    image_file = db.Column(db.String, nullable=False, default="default.jpg")
    password = db.Column(db.String, nullable=False)
    posts = db.relationship('Post', backref="author", lazy=True)

    def __repr__(self):
        return f'USER({self.username}, {self.email}, {self.image_file})'
コード例 #24
0
ファイル: models.py プロジェクト: LeeKLTW/flask_blog
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref=db.backref('author', lazy=True))  # "P" Upper case for  Class

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #25
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)
	comments = db.relationship('PostComment', backref='comment_post', lazy=True)

	def __repr__(self):
		return f"Post('{self.title}', '{self.date_posted}')"
コード例 #26
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.ForeignKey(User.id), nullable=False)
    title = db.Column(db.String(30), unique=True, nullable=False, server_default='Untitled')
    author = db.relationship(User, lazy=True, backref='post')
    created = db.Column(db.DateTime, nullable=False, server_default=db.func.current_timestamp())
    body = db.Column(db.Text, nullable=False)

    def __repr__(self):
        return '<Post %r>' % self.title
コード例 #27
0
ファイル: entries.py プロジェクト: kenken1199/bookshelf
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(50))

    entries = db.relationship("Entry", backref="users")

    def __init__(self, username=None, password=None):
        self.username = username
        self.password = password
コード例 #28
0
ファイル: models.py プロジェクト: CoryHuckeba/flaskBlog
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

    posts = db.relationship('Post', backref='category')

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

    def __repr(self):
        return self.name
コード例 #29
0
ファイル: models.py プロジェクト: annalun/flask_course
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(80))
    email = db.Column(db.String(35), unique=True)
    username = db.Column(db.String(25), unique=True)
    password = db.Column(db.String(60))
    is_author = db.Column(db.Boolean)

    posts = db.relationship('Post', backref='author', lazy='dynamic')
    comments = db.relationship('Comment', backref='author', lazy='dynamic')
    
    def __init__(self, fullname, email, username, password, is_author=False):
        self.fullname = fullname
        self.email = email
        self.username = username
        self.password = password
        self.is_author = is_author

    def __repr__(self):
        return '<Author %r>' % self.username
コード例 #30
0
class Blog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    admin = db.Column(db.Integer, db.ForeignKey('author.id'))
    posts = db.relationship('Post', backref='blog', lazy='dynamic')

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

    def __repr__(self):
        return '<Name %r>' % self.name