예제 #1
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key = True)
    username = db.Column(db.String(200),nullable=False)
    password = db.Column(db.String(200),nullable=False)
    created_at = db.Column(db.DateTime,nullable=False,default=datetime.now)
    updated_at = db.Column(db.DateTime,nullable=False,default=datetime.now,onupdate=datetime.now)


#Class User
#id,username,password,created_at,updated_at, age,
예제 #2
0
파일: models.py 프로젝트: shodee818/pytweet
class Post(db.Model):

    __tablename__ = "post"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    comments = db.relationship('Comment', backref="post", lazy=True)
    post = db.Column(db.String(1000), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
예제 #3
0
class Friendships(db.Model):

    __tablename__ = 'friendships'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer)
    user_following_id = db.Column(db.Integer,
                                  db.ForeignKey('users.id'),
                                  nullable=False)

    create_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    update_at = db.Column(db.DateTime,
                          nullable=False,
                          default=datetime.now,
                          onupdate=datetime.now)
예제 #4
0
파일: models.py 프로젝트: tenga1125/pytweet
class Profile(db.Model):

    __tablename__ = "profile"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    first_name = db.Column(db.String(255), nullable=False)
    last_name = db.Column(db.String(255), nullable=False)
    address = db.Column(db.String(255), nullable=False)
    occupation = db.Column(db.String(255), nullable=False)
    birthday = db.Column(db.String(255), nullable=False)
    skills = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
예제 #5
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key = True)
    username = db.Column(db.String(200),nullable=False)
    password = db.Column(db.String(200),nullable=False)
    created_at = db.Column(db.DateTime,nullable=False,default=datetime.now)
    updated_at = db.Column(db.DateTime,nullable=False,default=datetime.now,onupdate=datetime.now)
    name = db.Column(db.String(200),nullable=False)
    address = db.Column(db.String(200),nullable=False)
    contact_number = db.Column(db.String(200),nullable=False)
예제 #6
0
파일: models.py 프로젝트: tenga1125/pytweet
class User(UserMixin, db.Model):

    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(255), nullable=False)
    username = db.Column(db.String(255), nullable=False)  #nullable=空白
    password = db.Column(db.String(255), nullable=False)
    # sessionのところ
    posts = db.relationship('Post', backref='author', lazy=True)  #profileの

    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)

    def __init__(self, fullname, username, password):
        self.fullname = fullname
        self.username = username
        self.password = password

    def is_active(self):
        return True

    def is_authenticated(self):
        return True
예제 #7
0
class Posts(db.Model):

    __tablename__ = 'posts'

    id = db.Column(db.Integer,primary_key=True)
    user_id = db.Column(db.Integer,db.ForeignKey('users.id'),nullable=False)
    title = db.Column(db.String(250),nullable=False)
    content= db.Column(db.String(250),nullable=False)
    likes = db.Column(db.String(250),nullable=False)
    created_at = db.Column(db.DateTime,nullable=False,default=datetime.now)
    updated_at = db.Column(db.DateTime,nullable=False,default=datetime.now,onupdate=datetime.now)
예제 #8
0
파일: models.py 프로젝트: tenga1125/pytweet
class Comments(db.Model):
    __tablename__ = "comments"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'),
                        nullable=False)  # commentを1つだけ表示のため
    comment = db.Column(db.String(1000), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
예제 #9
0
class Comments(db.Model):

    __tablename__ = 'comments'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey('posts.id'), nullable=False)
    comment = db.Column(db.String(280), nullable=False)

    create_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    update_at = db.Column(db.DateTime,
                          nullable=False,
                          default=datetime.now,
                          onupdate=datetime.now)
예제 #10
0
class User(db.Model, UserMixin
           ):  # this UserMixin is for our login to keep the session data

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(200), nullable=True)
    bio = db.Column(db.String(280), nullable=True)

    create_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    update_at = db.Column(db.DateTime,
                          nullable=False,
                          default=datetime.now,
                          onupdate=datetime.now)

    posts = db.relationship(('Posts'), backref="editor_posts", lazy=True)
    comments = db.relationship(('Comments'),
                               backref="editor_comments",
                               lazy=True)
    friendship = db.relationship(('Friendships'),
                                 backref="friendships",
                                 lazy=True)

    friends = db.relationship(
        'User',
        secondary=followtable,
        primaryjoin=(followtable.c.source_user_id == id),
        secondaryjoin=(followtable.c.target_user_id == id),
        backref=db.backref("users", lazy="dynamic"),
        lazy="dynamic")

    # primaryjoin=id==friendship.c.source_user_id,
    # secondaryjoin=id==friendship.c.target_user_id)
    # select * from user join followtable on user.id = followtable.source_user_id

    def follow(self, friend):  # friend, the argument is User instance
        if friend not in self.friends:
            self.friends.append(friend)
            # friend.friends.append(self)

    def un_follow(self, friend):
        if friend in self.friends:
            self.friends.remove(friend)
예제 #11
0
파일: models.py 프로젝트: shodee818/pytweet
class User(UserMixin, db.Model):

    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(255), nullable=False)
    username = db.Column(db.String(255), nullable=False)
    password = db.Column(db.String(255), nullable=False)

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

    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
예제 #12
0
class Posts(db.Model):

    __tablename__ = 'posts'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    title = db.Column(db.String(30), nullable=False)
    content = db.Column(db.String(280), nullable=False)

    create_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    update_at = db.Column(db.DateTime,
                          nullable=False,
                          default=datetime.now,
                          onupdate=datetime.now)

    comments = db.relationship(('Comments'), backref="author", lazy=True)
예제 #13
0
# inherting db, creating the database table, creating modes
from pytweet.database import db

from datetime import datetime
from flask_login import UserMixin

followtable = db.Table(
    'followtable',
    db.Column('source_user_id',
              db.Integer,
              db.ForeignKey('users.id'),
              index=True),
    db.Column('target_user_id',
              db.Integer,
              db.ForeignKey('users.id'),
              index=True),
    db.UniqueConstraint('source_user_id',
                        'target_user_id',
                        name='unique_friendships'))


class User(db.Model, UserMixin
           ):  # this UserMixin is for our login to keep the session data

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(200), nullable=True)
    bio = db.Column(db.String(280), nullable=True)