diff --git a/app/__init__.py b/app/__init__.py index bbd9534..f9a5a00 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -5,13 +5,13 @@ db = SQLAlchemy() -def create_app(): +def create_app() -> Flask: app = Flask(__name__) app.config.from_object(Config) db.init_app(app) @app.route("/") - def home(): + def home() -> str: return render_template("index.html") with app.app_context(): diff --git a/app/config.py b/app/config.py index 06d2ed7..48dad6d 100644 --- a/app/config.py +++ b/app/config.py @@ -1,4 +1,5 @@ import os +from typing import Optional from dotenv import load_dotenv load_dotenv() @@ -12,5 +13,6 @@ class Config: SQLALCHEMY_DATABASE_URI (str): URL untuk koneksi pada database yang diambil dari variabel "DATABASE_URL" yang ada di .env. SQLALCHEMY_TRACK_MODIFICATIONS (bool): Menonaktifkan pelacakan pada perubahan object untuk mencegah terjadinya overhead. """ - SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL") - SQLALCHEMY_TRACK_MODIFICATIONS = False + + SQLALCHEMY_DATABASE_URI: str | None = os.getenv("DATABASE_URL") + SQLALCHEMY_TRACK_MODIFICATIONS: bool = False diff --git a/app/models.py b/app/models.py index 63bc0cb..a219873 100644 --- a/app/models.py +++ b/app/models.py @@ -10,8 +10,8 @@ class Provinces(db.Model): name (str): Nama Provinsi yang tidak boleh kosong. """ - code = db.Column(db.String(2), primary_key=True) - name = db.Column(db.String(255), nullable=False) + code: str = db.Column(db.String(2), primary_key=True) + name: str = db.Column(db.String(255), nullable=False) class Regencies(db.Model): @@ -24,11 +24,11 @@ class Regencies(db.Model): name (str): Nama Kabupaten/Kota yang tidak boleh kosong. """ - code = db.Column(db.String(5), primary_key=True) - province_code = db.Column( + code: str = db.Column(db.String(5), primary_key=True) + province_code: str = db.Column( db.String(2), db.ForeignKey("provinces.code"), nullable=False ) - name = db.Column(db.String(255), nullable=False) + name: str = db.Column(db.String(255), nullable=False) province = db.relationship("Provinces", backref=db.backref("regencies", lazy=True)) @@ -42,11 +42,11 @@ class Districts(db.Model): name (str): Nama Kecamatan yang tidak boleh kosong. """ - code = db.Column(db.String(8), primary_key=True) - regency_code = db.Column( + code: str = db.Column(db.String(8), primary_key=True) + regency_code: str = db.Column( db.String(5), db.ForeignKey("regencies.code"), nullable=False ) - name = db.Column(db.String(255), nullable=False) + name: str = db.Column(db.String(255), nullable=False) regency = db.relationship("Regencies", backref=db.backref("districts", lazy=True)) @@ -60,9 +60,9 @@ class Villages(db.Model): name (str): Nama Desa yang tidak boleh kosong. """ - code = db.Column(db.String(13), primary_key=True) - district_code = db.Column( + code: str = db.Column(db.String(13), primary_key=True) + district_code: str = db.Column( db.String(8), db.ForeignKey("districts.code"), nullable=False ) - name = db.Column(db.String(255), nullable=False) + name: str = db.Column(db.String(255), nullable=False) district = db.relationship("Districts", backref=db.backref("villages", lazy=True))