summaryrefslogtreecommitdiff
path: root/app/models.py
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2022-07-03 20:21:02 +0200
committerMarius Peter <marius.peter@tutanota.com>2022-07-03 20:21:02 +0200
commiteba4c1a3113d24319bccc5c52d4d93838334bd31 (patch)
treefe95881d42a0b4191a9371f82eaf66b9390af047 /app/models.py
parent5160b8a3ac9fc27c2b31206aed735a15de0099e9 (diff)
db now in models; modules.
Diffstat (limited to 'app/models.py')
-rw-r--r--app/models.py45
1 files changed, 22 insertions, 23 deletions
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"<Invoice for {self.customer.name} at {self.updated}>"
+ return f"<Invoice for {self.customer.name} billed {self.date_billed}>"
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"<Order {self.name} at {self.updated}>"
+ return f"<Order {self.name} at {self.date_time_created}>"
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"<Log ID {self.primary_key}>"
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"<Target ID {self.primary_key}>"
Copyright 2019--2024 Marius PETER