aboutsummaryrefslogtreecommitdiffstats
path: root/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'models.py')
-rw-r--r--models.py91
1 files changed, 77 insertions, 14 deletions
diff --git a/models.py b/models.py
index a302997..92a614a 100644
--- a/models.py
+++ b/models.py
@@ -8,15 +8,62 @@ Created on Sun Jan 17 09:56:14 2021
from app import db
from sqlalchemy.orm import relationship, backref
+import sqlalchemy.types as types
+
+
+def convert_date_to_string(converted_date):
+ if converted_date == 0:
+ return converted_date
+ else:
+ separated_string = converted_date.split("-")
+ converted_string = "".join([separated_string[2], ". ", convert_month_to_string(separated_string[1]), " ", separated_string[0]])
+ return converted_string
+
+def convert_month_to_string(my_month):
+ if my_month == "01":
+ return "ledna"
+ elif my_month == "02":
+ return "února"
+ elif my_month == "03":
+ return "března"
+ elif my_month == "04":
+ return "dubna"
+ elif my_month == "05":
+ return "května"
+ elif my_month == "06":
+ return "června"
+ elif my_month == "07":
+ return "července"
+ elif my_month == "08":
+ return "srpna"
+ elif my_month == "09":
+ return "září"
+ elif my_month == "10":
+ return "října"
+ elif my_month == "11":
+ return "listopadu"
+ elif my_month == "12":
+ return "prosince"
+ else:
+ return "podivného měsíce"
+
+class MyType(types.TypeDecorator):
+ '''Prefixes Unicode values with "PREFIX:" on the way in and
+ strips it off on the way out.
+ '''
+
+ impl = types.Unicode
+
+ def process_bind_param(self, value, dialect):
+ return convert_date_to_string(value)
+
+ def process_result_value(self, value, dialect):
+ # return "PREFIX:" + value
+ return convert_date_to_string(value)
+
+ def copy(self, **kw):
+ return MyType(self.impl.length)
-# class Soud(db.Model):
-# __tablename__ = "soudy"
-# id = db.Column(db.Integer, primary_key=True)
-# name = db.Column(db.String)
-
-# def __repr__(self):
-# # return "<soud: {}="">".format(self.name)
-# return self.name
association_table = db.Table("obce_relation",
db.Column("company_id", db.Integer, db.ForeignKey("companies.id"), primary_key=True, nullable=False),
@@ -47,9 +94,19 @@ class Predmety_Podnikani_Association(db.Model):
__tablename__ = 'predmety_podnikani_relation'
company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), nullable=False)
predmet_podnikani_id = db.Column(db.Integer, db.ForeignKey('predmety_podnikani.id'), nullable=False, primary_key=True)
- zapis_datum = db.Column(db.String)
- child = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani")
- parent = db.relationship("Company", back_populates="predmet_podnikani")
+ zapis_datum = db.Column(MyType)
+ vymaz_datum = db.Column(MyType)
+ predmet_podnikani = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani")
+ company = db.relationship("Company", back_populates="predmet_podnikani")
+
+class Predmety_Cinnosti_Association(db.Model):
+ __tablename__ = 'predmety_cinnosti_relation'
+ company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), nullable=False)
+ predmet_cinnosti_id = db.Column(db.Integer, db.ForeignKey('predmety_cinnosti.id'), nullable=False, primary_key=True)
+ zapis_datum = db.Column(MyType)
+ vymaz_datum = db.Column(MyType)
+ predmet_cinnosti = db.relationship("Predmet_Cinnosti", back_populates="company_predmet_cinnosti")
+ company = db.relationship("Company", back_populates="predmet_cinnosti")
class Company(db.Model):
@@ -66,7 +123,8 @@ class Company(db.Model):
ulice = db.relationship("Ulice", secondary=ulice_association, backref="companies")
pravni_forma = db.relationship("Pravni_Forma", secondary=pravni_forma_association, backref="companies")
insolvence = db.relationship("Insolvency_Events", backref="companies")
- predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="parent", lazy="joined")
+ predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="company", lazy="joined")
+ predmet_cinnosti = db.relationship("Predmety_Cinnosti_Association", back_populates="company", lazy="joined")
class Obce(db.Model):
@@ -94,9 +152,14 @@ class Insolvency_Events(db.Model):
company = relationship("Company", backref="insolvency_events")
insolvency_event = db.Column(db.String)
-
class Predmet_Podnikani(db.Model):
__tablename__ = "predmety_podnikani"
id = db.Column(db.Integer, primary_key=True)
predmet_podnikani = db.Column(db.String)
- company_predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="child", lazy="joined")
+ company_predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="predmet_podnikani", lazy="joined")
+
+class Predmet_Cinnosti(db.Model):
+ __tablename__ = "predmety_cinnosti"
+ id = db.Column(db.Integer, primary_key=True)
+ predmet_cinnosti = db.Column(db.String)
+ company_predmet_cinnosti = db.relationship("Predmety_Cinnosti_Association", back_populates="predmet_cinnosti", lazy="joined")