Пример #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    usernamephone_number = db.Column(db.String(150),
                                     nullable=False,
                                     unique=True,
                                     default="")
    username = db.Column(db.String(150),
                         nullable=False,
                         unique=True,
                         default="")
    email = db.Column(db.String(150), nullable=False, unique=True, default="")
    password = db.Column(db.String(256), nullable=False, default="")

    def __init__(self, usernamephone_number, username, email, password):
        self.usernamephone_number = usernamephone_number
        self.username = username
        self.email = email
        self.password = self.set_password(password)

    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash

    def __repr__(self):
        return f'{self.phone_number} has been created.'
Пример #2
0
class User(db.Model, UserMixin):
    # setting id to primary key
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(150), unique=True, nullable=False)
   
    email = db.Column(db.String(151), unique=True, nullable=False)

    password = db.Column(db.String(256), nullable=False)

    #Helping to set up the FK a many to one relationship
    phone = db.relationship('Phone', backref='author', lazy=True )

    def __init__(self,username,email,password):
        self.username= username
        #self.realname= realname
        self.email = email

        self.password = self.set_password(password)
    
    # don't want passwords in our database
    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash
     

    def __repr__(self):
        return f'{self.username} has been created with {self.email} '
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(150), nullable = False, unique=True)
    phone = db.Column(db.String(150), nullable = False, unique=True)
    email = db.Column(db.String(150), nullable = False, unique = True)
    password = db.Column(db.String(256), nullable = False)
    post = db.relationship('Post', backref = 'author', lazy = True)

    def __init__(self,name,phone,email,password):
        self.name = name
        self.phone = phone
        self.email = email
        self.password = self.set_password(password)

    def set_password(self,password):
        """
            Grab the password that is passed into the method
            return the hashed version of the password
            which will be stored inside the database
        """
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash

    def __repr__(self):
        return f'{self.name} has been created with the following email: {self.email}'
Пример #4
0
class PhoneNumber(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    phone_numb = db.Column(db.String(50))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

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

    def __repr__(self):
        return f"The Avenger is {self.name} \n and the phone number is {self.phone_numb}"
Пример #5
0
class Phone(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    realname = db.Column(db.String(300))
    alt_phone = db.Column(db.String(15))
    #ALWAYS SAVE DATETIME AS UTC TIME  saves issues down the road.
    date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = False)

    def __init__(self, realname, alt_phone, user_id):
        self.realname = realname
        self.alt_phone = alt_phone
        self.user_id = user_id

    #this will print in terminal 99% of the time
    def __repr__(self):
        return f'Actual name is {self.realname} \n and the contact number is {self.alt_phone}'
class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(100))
    content = db.Column(db.String(300))
    date_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow)
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'), nullable = False)
    # CREATE TABLE post(
    #    id SERIAL PRIMARY,
    #    title VARCHAR(100),
    #    content VARCHAR(300),
    #    date_created DATE DEFAULT CURRENT_DATE,
    #    user_id INTEGER NOT NULL,
    #    FOREIGN KEY(user_id) REFERENCES user(user_id)
    #);

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

    def __repr__(self):
        return f'The title of the post is {self.title} \n and the content is {self.content}'