From eba4c1a3113d24319bccc5c52d4d93838334bd31 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 3 Jul 2022 20:21:02 +0200 Subject: db now in models; modules. --- app/models.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'app/models.py') diff --git a/app/models.py b/app/models.py index 5155ee5..009e507 100644 --- a/app/models.py +++ b/app/models.py @@ -7,8 +7,8 @@ from flask_sqlalchemy import SQLAlchemy from datetime import datetime from flask_login import UserMixin -from . import db +db = SQLAlchemy() # Base = declarative_base() @@ -196,7 +196,7 @@ class Invoice(db.Model): self.amount_tax = amount_tax def __repr__(self): - return f"" + return f"" class Order(db.Model): # TODO @@ -212,36 +212,30 @@ class Order(db.Model): # TODO date_time_updated = db.Column( "DateTimeUpdated", db.String, server_onupdate=date_time_now() ) - product_id = db.Column( - "ProductId", - db.Integer, - db.ForeignKey("Product.ProductId"), - nullable=False, - ) customer_id = db.Column( "CustomerId", db.Integer, db.ForeignKey("Customer.CustomerId"), nullable=False, ) + product_id = db.Column( + "ProductId", + db.Integer, + db.ForeignKey("Product.ProductId"), + nullable=False, + ) invoice_id = db.Column( "InvoiceId", db.Integer, db.ForeignKey("Invoice.InvoiceId"), nullable=True, ) - customer = db.relationship( - "Customer", back_populates="orders" - ) - product = db.relationship( - "Product", back_populates="orders" - ) - invoice = db.relationship( - "Invoice", back_populates="orders" - ) + customer = db.relationship("Customer", back_populates="orders") + product = db.relationship("Product", back_populates="orders") + invoice = db.relationship("Invoice", back_populates="orders") def __repr__(self): - return f"" + return f"" class Product(db.Model): @@ -283,7 +277,7 @@ class Product(db.Model): class FertiLog(db.Model): - __tablename__ = "Fertilog" + __tablename__ = "FertiLog" primary_key = db.Column("FertiLogId", db.Integer, primary_key=True) nno3 = db.Column("NNO3", db.Float, default=0) p = db.Column("P", db.Float, default=0) @@ -307,6 +301,8 @@ class FertiLog(db.Model): date_time_updated = db.Column( "DateTimeUpdated", db.String, server_onupdate=date_time_now() ) + targets = db.relationship("FertiTarget", back_populates="ferti_log") + def __init__(self, nno3, p, k, ca, mg, s, na, cl, fe, zn, b, mn, cu, mo, si, nnh4): self.nno3 = nno3 @@ -325,18 +321,21 @@ class FertiLog(db.Model): self.mo = mo self.si = si self.nnh4 = nnh4 - self.date_time_created = date_time_now def __repr__(self): return f"" class FertiTarget(FertiLog): - __tablename__ = "Fertitarget" + __tablename__ = "FertiTarget" primary_key = db.Column("FertiTargetId", db.Integer, primary_key=True) - targeted_log = db.Column( - "FertiLogId", db.Integer, db.ForeignKey("Fertilog.FertiLogId") + ferti_log_id = db.Column( + "FertiLogId", db.Integer, db.ForeignKey("FertiLog.FertiLogId") ) + ferti_log = db.relationship("FertiLog", back_populates="targets") + + # def __init__(self): + # super(*args).__init__() def __repr__(self): return f"" -- cgit v1.2.3