Esempio n. 1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64),
                         index=True,
                         unique=True,
                         nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)

    def __repr__(self):
        return '<User {}>'.format(self.username)
Esempio n. 2
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)
    password = db.Column(db.String(60), nullable=False)
    #Profile picture
    image_file = db.Column(db.String(20), nullable=False, default="default.jpg")

    #Lazy will load all posts from single user in one go
    photos = db.relationship("Post", backref="author", lazy=True)

    #User object print formatting
    def __repr__(self):
        format = "User (username: "******", email: " + str(self.email) + ", profile picture: " + str(self.image_file) + ")"
        return format
Esempio n. 3
0
class Photo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    image_file = db.Column(db.String(20), nullable=False)
    photo_order = db.Column(db.Integer, nullable=False)

    #post id in post model acts as foreign key in photo model
    post_id = db.Column(db.Integer, db.ForeignKey("post.id"), nullable=False)

    def __repr__(self):
        format = "Photo (post photo: " + self.image_file + ")"
        return format
Esempio n. 4
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)
    is_private = db.Column(db.Boolean, nullable=False)
    tag = db.Column(db.String, nullable=True)
    photos_contained = db.Column(db.String, nullable=False)

    #id in user model acts as foreign key in Post model
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)

    #Lazy will load all photos from single post in one go
    photos = db.relationship("Photo", backref="parent", lazy=True)

    #Post object print formatting
    def __repr__(self):
        format = "Post (title: " + str(self.title) + ", date: " + str(self.date_posted)
        return format
Esempio n. 5
0
class Image(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    owner = db.relationship('User', backref=db.backref('images', lazy=True))
    filename = db.Column(db.String(64), index=True, nullable=False)
    private = db.Column(db.Boolean, nullable=False)