From b5b8b9bdbcc7f83d4a3e23b3e03e33cd08ee10a3 Mon Sep 17 00:00:00 2001 From: blendoit Date: Mon, 3 Feb 2020 02:06:13 -0800 Subject: Homepage load animations 2. --- app/routes.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'app/routes.py') diff --git a/app/routes.py b/app/routes.py index e520602..67b9359 100644 --- a/app/routes.py +++ b/app/routes.py @@ -16,6 +16,7 @@ Personal imports: These are used to avoid cluttering this file with placeholder data for posts' content. """ +from datetime import datetime from flask import Flask, render_template, flash, redirect, url_for from forms import RegistrationForm, LoginForm from flask_sqlalchemy import SQLAlchemy @@ -26,11 +27,37 @@ from placeholder_messages import messages app = Flask(__name__) app.config['SECRET_KEY'] = 'Scooby_Lu,_where_are_you?' -app.config['SQLALCHEMY_DATABASE_URI'] = 'mariadb:///site.db' - +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' db = SQLAlchemy(app) +class Alias(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.png') + password = db.Column(db.String(60), nullable=False) + posts = db.relationship('Post', backref='author', lazy=True) + + def __repr__(self): + return f"Alias('{self.username}','{self.email}','{self.image_file}' )" + + +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('alias.id'), nullable=False) + + def __repr__(self): + return f"Post('{self.title}', '{self.date_posted}')" + + @app.route("/") @app.route("/home") def home(): -- cgit v1.2.3