Skip to content

Commit 67f31e9

Browse files
committed
Resolve User data model.
1 parent 1d674e4 commit 67f31e9

File tree

7 files changed

+14
-10
lines changed

7 files changed

+14
-10
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ run: env
3838
install: env
3939
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
4040
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
41-
npm i -g less && \
4241
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4342

4443
.PHONY: deploy

config.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""Flask configuration variables."""
2-
from os import environ
2+
from os import environ, path
3+
4+
from dotenv import load_dotenv
5+
6+
BASE_DIR = path.abspath(path.dirname(__file__))
7+
load_dotenv(path.join(BASE_DIR, ".env"))
38

49

510
class Config:
@@ -11,7 +16,6 @@ class Config:
1116
# Flask Config
1217
FLASK_APP = "main.py"
1318
FLASK_DEBUG = environ.get("FLASK_DEBUG")
14-
FLASK_ENV = environ.get("FLASK_ENV")
1519

1620
# Database
1721
SQLALCHEMY_DATABASE_URI = environ.get("SQLALCHEMY_DATABASE_URI")

flask_sqlalchemy_tutorial/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def create_app():
99
"""Construct the core application."""
1010
app = Flask(__name__, instance_relative_config=False)
1111
app.config.from_object("config.Config")
12+
print(app.config)
1213

14+
# Initialize Database Plugin
1315
db.init_app(app)
1416

1517
with app.app_context():

flask_sqlalchemy_tutorial/models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
class User(db.Model):
66
"""User account data model."""
77

8-
__tablename__ = "user"
8+
__tablename__ = "flasksqlalchemy-tutorial-users"
99

1010
id = db.Column(db.Integer, primary_key=True)
1111
username = db.Column(db.String(64), index=True, unique=True, nullable=False)
1212
email = db.Column(db.String(80), index=True, unique=True, nullable=False)
13-
created = db.Column(db.DateTime, nullable=False)
1413
bio = db.Column(db.Text, nullable=True)
1514
admin = db.Column(db.Boolean, nullable=False)
15+
created_at = db.Column(db.DateTime, server_default=db.func.now())
16+
updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())
1617

1718
def __repr__(self):
1819
return f"<User id={self.id}, username={self.username}, email={self.email}>"

flask_sqlalchemy_tutorial/routes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def user_records():
1313
username = request.args.get("user")
1414
email = request.args.get("email")
1515
if username and email:
16-
existing_user = User.query.filter(
17-
User.username == username or User.email == email
18-
).first()
16+
existing_user = User.query.filter(User.username == username or User.email == email).first()
1917
if existing_user:
2018
return make_response(f"{username} ({email}) already created!")
2119
new_user = User(

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
app = create_app()
55

66
if __name__ == "__main__":
7-
app.run(host="0.0.0.0", port=8089, debug=True, load_dotenv=True)
7+
app.run(host="0.0.0.0", port=8089, debug=False, load_dotenv=True)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ python-dotenv = "*"
2020
pytest = "*"
2121
black = "*"
2222
isort = "*"
23-
mypy = "^1.5.1"
23+
mypy = "*"
2424

2525
[tool.poetry.scripts]
2626
run = "main:app"

0 commit comments

Comments
 (0)